TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2609 8.41K
✅ SQL Aggregate Functions Questions with Answers Part-2 🚀📊

🔎 Q1. Find departments where the average salary is greater than 70,000.
🗂️ Table: "employees(emp_id, name, department_id, salary)"

✅ Answer:
SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 70000;


🔎 Q2. Count employees in each department having more than 5 employees.
🗂️ Table: "employees(emp_id, name, department_id)"

✅ Answer:
SELECT department_id, COUNT(*) AS total_employees
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;


🔎 Q3. Find the department with the highest total salary.
🗂️ Table: "employees(emp_id, department_id, salary)"

✅ Answer:
SELECT department_id
FROM employees
GROUP BY department_id
ORDER BY SUM(salary) DESC
LIMIT 1;


🔎 Q4. Get departments where the minimum salary is greater than 30,000.
🗂️ Table: "employees(emp_id, department_id, salary)"

✅ Answer:
SELECT department_id, MIN(salary) AS min_salary
FROM employees
GROUP BY department_id
HAVING MIN(salary) > 30000;


🔎 Q5. Find the difference between highest and lowest salary in each department.
🗂️ Table: "employees(emp_id, department_id, salary)"

✅ Answer:
SELECT department_id, MAX(salary) - MIN(salary) AS salary_difference
FROM employees
GROUP BY department_id;


Double Tap ♥️ For More
  • ❤ 28
More from @sqlspecialist
  1. Oct 9, 2026“Here, the data is sorted by the second column in descending order and the first five rows…
  2. Oct 9, 2026📊 Data Analyst Interview Series — Part 6 Guys, let's continue our Data Analyst Interview…
  3. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  4. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  5. Oct 7, 2026📊 Kandinsky 6.0 Video: AI-Powered Content Creation for Analysts The new Kandinsky 6.0 Vid…
  6. Oct 7, 2026Alternatively, depending on the Excel version and requirement, I could use functions such…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →