Sitemap
2 min readDec 8, 2025

--

๐ŸŽฏ ๐’๐๐‹ ๐’๐ž๐ซ๐ข๐ž๐ฌ | ๐„๐ฉ. ๐Ÿ– โ€” ๐‡๐€๐•๐ˆ๐๐†: ๐…๐ข๐ฅ๐ญ๐ž๐ซ๐ข๐ง๐  ๐†๐ซ๐จ๐ฎ๐ฉ๐ฌ, ๐๐จ๐ญ ๐‘๐จ๐ฐ๐ฌ

๐–๐ก๐ฒ ๐–๐‡๐„๐‘๐„ ๐‚๐š๐งโ€™๐ญ ๐‚๐š๐ญ๐œ๐ก ๐Ž๐ฏ๐ž๐ซ๐ฌ๐ฉ๐ž๐ง๐๐ข๐ง๐  ๐๐ซ๐จ๐ฃ๐ž๐œ๐ญ๐ฌ

๐Ÿง  ๐‡๐จ๐จ๐ค:
Imagine youโ€™re a Data Analyst at LinkedIn.
Youโ€™re reviewing project finances and need to ๐ข๐๐ž๐ง๐ญ๐ข๐Ÿ๐ฒ ๐ฉ๐ซ๐จ๐ฃ๐ž๐œ๐ญ๐ฌ ๐ญ๐ก๐š๐ญ ๐ฐ๐ž๐ง๐ญ ๐จ๐ฏ๐ž๐ซ ๐›๐ฎ๐๐ ๐ž๐ญ.
Seems simple? You just need to compare:
Total employee cost per project vs. Project budget

But hereโ€™s the twist โ€” employees work on different projects for different durations, and you need to ๐ฉ๐ซ๐จ๐ซ๐š๐ญ๐ž their annual salaries before summing them up.

And once youโ€™ve calculated total costs per project, you need to ๐Ÿ๐ข๐ฅ๐ญ๐ž๐ซ ๐จ๐ง๐ฅ๐ฒ ๐ญ๐ก๐จ๐ฌ๐ž ๐ฉ๐ซ๐จ๐ฃ๐ž๐œ๐ญ๐ฌ ๐ฐ๐ก๐ž๐ซ๐ž ๐œ๐จ๐ฌ๐ญ๐ฌ ๐ž๐ฑ๐œ๐ž๐ž๐ ๐ญ๐ก๐ž ๐›๐ฎ๐๐ ๐ž๐ญ โ€” Thatโ€™s when ๐‡๐€๐•๐ˆ๐๐† becomes your hero. ๐Ÿš€

๐Ÿ’ก ๐‚๐จ๐ง๐œ๐ž๐ฉ๐ญ:
The ๐‡๐€๐•๐ˆ๐๐† clause filters results ๐š๐Ÿ๐ญ๐ž๐ซ ๐š๐ ๐ ๐ซ๐ž๐ ๐š๐ญ๐ข๐จ๐ง, unlike ๐–๐‡๐„๐‘๐„ , which filters rows ๐›๐ž๐Ÿ๐จ๐ซ๐ž ๐š๐ ๐ ๐ซ๐ž๐ ๐š๐ญ๐ข๐จ๐ง.

๐Ÿงฉ ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ: ๐‘๐ข๐ฌ๐ค๐ฒ ๐๐ซ๐จ๐ฃ๐ž๐œ๐ญ๐ฌ โ€” https://lnkd.in/e92_5JKx

๐“๐š๐ฌ๐ค: Find projects where total prorated salary cost of assigned employees exceeds the projectโ€™s budget.

Press enter or click to view image in full size

๐‹๐จ๐ ๐ข๐œ ๐๐ซ๐ž๐š๐ค๐๐จ๐ฐ๐ง:

1๏ธโƒฃ Calculate how long each project lasted (in days).
2๏ธโƒฃ Prorate each employeeโ€™s annual salary for their duration on that project.
3๏ธโƒฃ Sum total prorated cost per project.
4๏ธโƒฃ Compare that total cost with the projectโ€™s budget.
5๏ธโƒฃ Keep only projects where cost > budget โ†’ use HAVING.

๐Ÿ’ป๐’๐๐‹ ๐’๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง:

Get Somyaguptaโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

with project_emp as (Select p.title,
p.budget,
(p.end_date โ€” p.start_date)*(e.salary/365.0) as employee_salary_perproject,
e.salary
from
linkedin_projects p join linkedin_emp_projects ep
on p.id=ep.project_id join linkedin_employees e on
e.id=ep.emp_id)

select title,budget,ceil(sum(employee_salary_perproject)) as prorated_employee_expense from project_emp
group by title, budget having
budget(ceil(sum(employee_salary_perproject)) order by title;

โœ… ๐†๐‘๐Ž๐”๐ ๐๐˜ โ†’ Groups data by project.
โœ… ๐’๐”๐Œ() โ†’ Aggregates prorated salary per project.
โœ… ๐‡๐€๐•๐ˆ๐๐† โ†’ Filters projects exceeding budget.
โœ… ๐‚๐„๐ˆ๐‹() โ†’ Rounds cost up to the nearest dollar for reporting accuracy.

๐Ÿ’ฌ ๐๐ฎ๐ฌ๐ข๐ง๐ž๐ฌ๐ฌ ๐ˆ๐ง๐ฌ๐ข๐ ๐ก๐ญ:

The HAVING clause helps financial analysts, PMOs, and operations teams quickly:

โžก๏ธ Spot departments exceeding cost limits
โžก๏ธ Identify stores or campaigns performing above or below thresholds

This is how SQL turns data into action.

๐Ÿงฉ ๐“๐ซ๐ฒ ๐’๐ข๐ฆ๐ข๐ฅ๐š๐ซ ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:

1๏ธโƒฃ Marketing Campaign Success โ€” https://lnkd.in/eAVZcfQU
2๏ธโƒฃ Actor Rating Difference Analysis โ€” https://lnkd.in/eAGx8QsG

๐Ÿš€ ๐‚๐จ๐ฆ๐ข๐ง๐  ๐๐ž๐ฑ๐ญ:

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

Have you ever used HAVING to catch an anomaly or threshold breach in real data?

--

--