QuizzesHAVING Clause — Concept Check
intermediate
mysql

HAVING Clause — Concept Check

Questions on HAVING Clause. HAVING filters groups after aggregation (unlike WHERE which filters rows before); it can reference aggregate expressions that are not valid in WHERE.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on HAVING Clause — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A database query is running slowly. It uses a HAVING clause to filter rows before aggregation. What should you do to improve performance?

    • AAdd more indexes to the database
    • BIncrease server memory
    • CMove the filter condition to the WHERE clause
    • DUse a different aggregate function
  2. 2.In a report, you need to list products with an average rating below 3 and at least 10 reviews. Which clause should you use to filter these conditions?

    • AHAVING avg_rating < 3 OR review_count >= 10
    • BWHERE avg_rating < 3 OR review_count >= 10
    • CHAVING avg_rating < 3 AND review_count >= 10
    • DWHERE avg_rating < 3 AND review_count >= 10
  3. 3.You want to find departments with more than 50 employees and an average salary over $70,000. Where should you place the conditions?

    • AHAVING for both conditions
    • BHAVING for employee count, WHERE for average salary
    • CWHERE for employee count, HAVING for average salary
    • DWHERE for both conditions
  4. 4.A query uses HAVING to filter orders with a total spend over $1000. What happens if you move this condition to WHERE?

    • AThe query will run faster
    • BThe query will fail due to invalid syntax
    • CThe query will return incorrect results
    • DThe query will ignore the condition
  5. 5.Which statement is true about using HAVING without GROUP BY?

    • AHAVING is ignored if GROUP BY is absent
    • BHAVING can filter the entire dataset as one group
    • CHAVING requires a GROUP BY clause
    • DHAVING without GROUP BY causes a syntax error
  6. 6.A query uses HAVING to filter customer IDs greater than 100. Why is this an anti-pattern?

    • AHAVING should not filter non-aggregate conditions
    • BHAVING is faster than WHERE
    • CHAVING cannot filter numeric values
    • DHAVING requires aggregate functions
  7. 7.When can SELECT aliases be used in a HAVING clause in MySQL 5.7+?

    • ASupported but non-standard
    • BAlways, as per SQL standard
    • CNever, it's not supported
    • DOnly in the WHERE clause
  8. 8.Which aggregate function can be used in a HAVING clause to filter groups?

    • ADISTINCT
    • BJOIN
    • CGROUP_CONCAT
    • DCOUNT