๐ฏ ๐๐๐ ๐๐๐ซ๐ข๐๐ฌ | ๐๐ฉ. ๐ โ ๐๐๐๐๐ ๐๐๐๐: ๐๐จ๐ง๐ง๐๐๐ญ๐ข๐ง๐ ๐๐๐๐ฅ๐๐ฌ ๐ญ๐จ ๐๐๐ฅ๐ฅ ๐ ๐๐ญ๐จ๐ซ๐ฒ
Every business insight starts with a question โ but often, ๐ญ๐ก๐ ๐๐ง๐ฌ๐ฐ๐๐ซ ๐ข๐ฌ ๐ก๐ข๐๐๐๐ง ๐๐๐ซ๐จ๐ฌ๐ฌ ๐ฆ๐ฎ๐ฅ๐ญ๐ข๐ฉ๐ฅ๐ ๐ญ๐๐๐ฅ๐๐ฌ.
Thatโs where ๐๐๐๐๐ ๐๐๐๐ steps in โ it connects the dots and turns isolated datasets into one powerful story.
Letโs see how ๐
๐ก๐๐จ๐ง๐๐๐ฉ๐ญ ๐๐ซ๐๐๐ค๐๐จ๐ฐ๐ง: ๐๐๐๐๐ ๐๐๐๐
๐๐๐๐๐ ๐๐๐๐ returns only the rows that have matching values in both tables.
Itโs like saying โ โShow me only the records that exist in both worlds.โ
This is the backbone of relational databases โ connecting ๐๐ฎ๐ฌ๐ญ๐จ๐ฆ๐๐ซ๐ฌ ๐ญ๐จ ๐ญ๐ก๐๐ข๐ซ ๐จ๐ซ๐๐๐ซ๐ฌ, ๐ฌ๐ญ๐ฎ๐๐๐ง๐ญ๐ฌ ๐ญ๐จ ๐ญ๐ก๐๐ข๐ซ ๐ ๐ซ๐๐๐๐ฌ, ๐จ๐ซ ๐ฎ๐ฌ๐๐ซ๐ฌ ๐ญ๐จ ๐ญ๐ก๐๐ข๐ซ ๐๐๐ญ๐ข๐จ๐ง๐ฌ.
๐ ๐๐ฑ๐๐ฆ๐ฉ๐ฅ๐: ๐๐ข๐ ๐ก๐๐ฌ๐ญ ๐๐จ๐ฌ๐ญ ๐๐ซ๐๐๐ซ๐ฌ โ https://lnkd.in/gz4nu4f4
๐งพ ๐๐ก๐ ๐๐ฎ๐๐ฌ๐ญ๐ข๐จ๐ง:
Find the customers with the highest daily total order cost between Feb 1, 2019 and May 1, 2019.
If a customer placed multiple orders on the same day, sum their total costs.
Return each customerโs ๐๐ข๐ซ๐ฌ๐ญ ๐ง๐๐ฆ๐, ๐๐๐ข๐ฅ๐ฒ ๐ญ๐จ๐ญ๐๐ฅ, ๐๐ง๐ ๐๐๐ญ๐ โ including ties.
๐ง ๐๐ก๐ ๐๐ฎ๐๐ซ๐ฒ:
Get Somyaguptaโs stories inย yourย inbox
Join Medium for free to get updates fromย thisย writer.
SELECT
c.first_name,
o.order_date,
SUM(o.total_order_cost) AS daily_total
FROM orders o
INNER JOIN customers c
ON o.cust_id = c.id
WHERE o.order_date BETWEEN โ2019โ02โ01โ AND โ2019โ05โ01โ
GROUP BY c.first_name, o.order_date
HAVING SUM(o.total_order_cost) = (
SELECT MAX(daily_sum)
FROM (SELECT order_date, SUM(total_order_cost) AS daily_sum
FROM orders
WHERE order_date BETWEEN โ2019โ02โ01โ AND โ2019โ05โ01โ
GROUP BY order_date, cust_id) t );
๐งฉ ๐๐๐ฒ ๐๐จ๐ข๐ง๐ญ๐ฌ:
โ
๐๐๐๐๐ ๐๐๐๐ links orders with customers through cust_id = id.
โ
The ๐๐๐๐๐ clause filters the time frame (FebโMay 2019).
โ
The first ๐๐๐๐๐ ๐๐ aggregates each customerโs daily total.
โ
The subquery finds the maximum daily spend across all customers and dates.
โ
The ๐๐๐๐๐๐ clause ensures we only keep those matching that highest value.
๐ฌ ๐๐ก๐ฒ ๐๐ญ ๐๐๐ญ๐ญ๐๐ซ๐ฌ:
In business, ๐๐๐๐๐ ๐๐๐๐ lets you answer multi-dimensional questions - ๐ง๐จ๐ญ ๐ฃ๐ฎ๐ฌ๐ญ ๐ฐ๐ก๐จ ๐จ๐ซ๐๐๐ซ๐๐, ๐๐ฎ๐ญ ๐ฐ๐ก๐๐ง, ๐ก๐จ๐ฐ ๐ฆ๐ฎ๐๐ก, ๐๐ง๐ ๐ก๐จ๐ฐ ๐ญ๐ก๐๐ฒ ๐๐จ๐ฆ๐ฉ๐๐ซ๐ ๐ญ๐จ ๐จ๐ญ๐ก๐๐ซ๐ฌ.
Youโre no longer just querying tables โ youโre uncovering stories of customer behavior and business value.
๐ ๐๐ซ๐ฒ ๐๐ญ ๐๐จ๐ฎ๐ซ๐ฌ๐๐ฅ๐:
๐ ๐๐๐ง๐๐ข๐ง๐ ๐ฏ๐ฌ. ๐๐ฉ๐๐ง๐ข๐ง๐ ๐๐ง๐๐ฉ๐ฌ (https://lnkd.in/gqmBsNi8)
๐ ๐๐๐ง๐ค ๐๐๐ซ๐ข๐๐ง๐๐ ๐๐๐ซ ๐๐จ๐ฎ๐ง๐ญ๐ซ๐ฒ (https://lnkd.in/gYCsAACk)
๐ ๐๐จ๐ฆ๐ข๐ง๐ ๐ฎ๐ฉ ๐ง๐๐ฑ๐ญ:
๐๐ฉ. ๐๐ โ ๐๐๐
๐, ๐๐๐๐๐ & ๐
๐๐๐ ๐๐๐๐๐ ๐๐๐๐: ๐๐๐๐ฉ๐ข๐ง๐ ๐๐ข๐ฌ๐ฌ๐ข๐ง๐ ๐๐๐ญ๐





