0
0
SQLquery~5 mins

Combining multiple aggregates in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the term aggregate function mean in SQL?
An aggregate function performs a calculation on a set of values and returns a single value, like SUM, COUNT, AVG, MIN, or MAX.
Click to reveal answer
beginner
How can you combine multiple aggregate functions in one SQL query?
You can list multiple aggregate functions separated by commas in the SELECT clause, for example: SELECT COUNT(*), AVG(price) FROM products;
Click to reveal answer
intermediate
Why do we use GROUP BY with aggregate functions?
GROUP BY groups rows that have the same values in specified columns so aggregate functions can calculate results for each group separately.
Click to reveal answer
intermediate
What will this query return? <br>SELECT department, COUNT(*), AVG(salary) FROM employees GROUP BY department;
It returns each department's name, the number of employees in that department, and the average salary of employees in that department.
Click to reveal answer
intermediate
Can you combine aggregate functions without GROUP BY? What happens?
Yes, you can combine aggregates without GROUP BY. The functions will calculate over the entire table and return one row with combined results.
Click to reveal answer
Which SQL clause is used to group rows for aggregate calculations?
AGROUP BY
BORDER BY
CWHERE
DHAVING
What does this query return? <br>SELECT COUNT(*), SUM(quantity) FROM sales;
AAverage quantity and total sales
BNumber of unique products and total quantity
CNumber of sales rows and total quantity sold
DList of sales rows
Can you use multiple aggregate functions in one SELECT statement?
AOnly if you use subqueries
BNo, only one aggregate per query
COnly with JOINs
DYes, separated by commas
What happens if you use aggregate functions without GROUP BY?
AIt groups by all columns automatically
BAggregates calculate over the whole table and return one row
CAggregates calculate per each row
DQuery returns an error
Which of these is NOT an aggregate function?
ASELECT
BMAX
CCOUNT
DSUM
Explain how to combine multiple aggregate functions in a single SQL query and when to use GROUP BY.
Think about how to get counts and averages per category.
You got /4 concepts.
    Describe what happens when you use aggregate functions without a GROUP BY clause.
    Consider the whole table as one group.
    You got /3 concepts.