COUNT and SUM
Two of the most useful SQL tools for summarizing data are COUNT()
and SUM()
.
They help you answer questions like:
- How many orders were placed?
- What's the total amount spent?
COUNT: How Many Rows?
COUNT()
is used to count rows in a table.
Count total clients
SELECT COUNT(*) FROM clients;
This returns the total number of rows in the clients
table.
To count only non-null values in a column, you can use the COUNT()
function with a column name.
Count clients with email
SELECT COUNT(email) FROM clients;
SUM: Add Up Values
SUM()
adds together values from a numeric column.
Total sales
SELECT SUM(order_total) FROM client_orders;
This returns the total amount spent across all orders.
Note: Works only with numeric types like
INT
orREAL
.
What's Next?
Next up: learn how to use AVG()
, MAX()
, and MIN()
to measure averages and find highest or lowest values.
Quiz
0 / 1
The SQL function SUM()
can be used to count the number of rows in a table.
True
False
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Tables
Execution Result