Group By & Having Interview Questions

    Question 1GROUP BY Purpose and Function

    What is the purpose of GROUP BY clause in SQL?

    Question 2HAVING vs WHERE Clause Usage

    What is the difference between HAVING and WHERE clauses?

    Question 3GROUP BY with HAVING Clause

    From an employees table (emp_id, name, department, salary), find departments with more than 5 employees and average salary greater than $60,000.

    Question 4SELECT Columns with GROUP BY Rule

    What is the rule for SELECT columns when using GROUP BY?

    Question 5GROUP BY with Multiple Columns

    How does GROUP BY work with multiple columns?

    Question 6HAVING without GROUP BY

    Can HAVING clause be used without GROUP BY?

    Question 7GROUP BY with Complex HAVING Conditions

    From a student_grades table (student_id, subject, grade, semester), find students who have taken more than 3 subjects and have an average grade between 85 and 95, showing student_id, subject count, and average grade.

    Question 8GROUP BY Multiple Columns with WHERE and HAVING

    From a sales table (sale_id, product_id, category, region, sale_amount, sale_date), find total sales by category and region for sales in 2023, showing only combinations with total sales exceeding $10,000.

    Question 9GROUP BY with NULL Values

    How does GROUP BY handle NULL values?

    Question 10Basic GROUP BY with Aggregate Functions

    From an orders table (order_id, customer_id, order_date, total_amount), find the total sales amount and number of orders for each customer.