CodeBlanks Logo Icon CodeBlanks

Low performers

Find low-performing categories with HAVING.

Low performance

To find low-performance days you use HAVING SUM(amount) < 500.

SELECT sale_date, SUM(amount) AS total
FROM sales
GROUP BY sale_date
HAVING SUM(amount) < 500;

This query returns days with revenue under 500.

sale_date, SUM(amount) AS total is selected from sales. Rows are grouped by sale_date; aggregate functions are computed per group. HAVING SUM(amount) < 500 runs after grouping and drops groups that fail the condition.

Low performance — details

Finding low-revenue days helps campaign planning. Filter them with HAVING.

For example, HAVING SUM(amount) < 500 lists the days with total sales below 500; weekends or holidays often show up here.

Practice Low performance

Find days with revenue under 500 using HAVING SUM(amount) < 500.

Starter code

query.sql
-- low revenue
SELECT sale_date, SUM(amount) AS total
FROM sales
GROUP BY sale_date

Sample solution

query.sql
SELECT sale_date, SUM(amount) AS total
FROM sales
GROUP BY sale_date
HAVING SUM(amount) < 500;

Expected output

sale_date   total
2026-01-03  300
2026-01-05  150

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Add HAVING

Question
SELECT sale_date, SUM(amount) AS total
FROM sales
GROUP BY sale_date
____ SUM(amount) < 500;
Answer
SELECT sale_date, SUM(amount) AS total
FROM sales
GROUP BY sale_date
HAVING SUM(amount) < 500;

Explanation: HAVING SUM(amount) < 500 shows the days with total sales below 500.

2 How is low revenue found?

  • HAVING SUM < 500 Correct answer
  • WHERE COUNT
  • ORDER BY DESC
  • DISTINCT

Explanation: Filter low totals with HAVING.

3 Low performers: match the terms

Term Meaning
HAVING filter
SUM sum
low small
GROUP BY group

All lessons in Intermediate