A table sales records individual sales in dollars:
sale_id
region
amount
1
North
120
2
80
3
150
4
South
90
5
200
6
East
110
7
130
8
60
9
West
300
The following query is run:
SELECT region, COUNT(*) AS big_sales, SUM(amount) AS big_total FROM sales WHERE amount >= 100 GROUP BY region HAVING COUNT(*) >= 2;
How many rows does the query return, and what are the highest and lowest values of big_total among the returned rows? Give each answer as a whole number, with the totals in dollars.
Unlock full course notes by signing up
AVG with NULL ratings
A table reviews stores product ratings in a NUMERIC column rating; a rating is NULL when the reviewer left a comment but no score.
What value does SELECT AVG(rating) FROM reviews WHERE product_id = 7; return? Give your answer to two decimal places.
COUNT variants with NULLs and duplicates
A university stores course enrolments in the table enrolments below, where a NULL grade means the grade has not yet been recorded.
The query SELECT COUNT(*), COUNT(grade), COUNT(DISTINCT student_id), COUNT(DISTINCT grade) FROM enrolments; is run. Enter each result as a whole number. COUNT(*) returns ________, COUNT(grade) returns ________, COUNT(DISTINCT student_id) returns ________, and COUNT(DISTINCT grade) returns ________.
Interpreting a HAVING clause with a subquery
A table employees(emp_id, dept, salary, hire_year) holds one row per employee. Consider this query:
Which of the following statements about this query are true? Select all that apply.
Grouping by two columns with a HAVING filter
A retailer records sales in the table orders below. A NULL amount marks an order whose payment has not yet been captured. Amounts are in whole dollars.
Give, as whole numbers, the number of groups that GROUP BY forms before HAVING is applied, the number of rows the query returns, the value of total in the first result row in dollars, and the value of total in the last result row in dollars.