Sitemap
2 min readDec 9, 2025

--

๐ŸŽฏ ๐’๐๐‹ ๐’๐ž๐ซ๐ข๐ž๐ฌ | ๐„๐ฉ. ๐Ÿ— โ€” ๐ˆ๐๐๐„๐‘ ๐‰๐Ž๐ˆ๐: ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ๐ข๐ง๐  ๐“๐š๐›๐ฅ๐ž๐ฌ ๐ญ๐จ ๐“๐ž๐ฅ๐ฅ ๐š ๐’๐ญ๐จ๐ซ๐ฒ

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)

๐Ÿš€ ๐‚๐จ๐ฆ๐ข๐ง๐  ๐ฎ๐ฉ ๐ง๐ž๐ฑ๐ญ:
๐„๐ฉ. ๐Ÿ๐ŸŽ โ€” ๐‹๐„๐…๐“, ๐‘๐ˆ๐†๐‡๐“ & ๐…๐”๐‹๐‹ ๐Ž๐”๐“๐„๐‘ ๐‰๐Ž๐ˆ๐: ๐Š๐ž๐ž๐ฉ๐ข๐ง๐  ๐Œ๐ข๐ฌ๐ฌ๐ข๐ง๐  ๐ƒ๐š๐ญ๐š

--

--