Lecture

COUNT and SUM

Two of the most common SQL functions for summarizing data are COUNT() and SUM(). They help you answer questions such as:

  • How many orders were placed?
  • What's the total amount spent?

COUNT: How Many Rows?

COUNT() returns the number of 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 specific column, use COUNT() with the column name.

Count clients with email
SELECT COUNT(email) FROM clients;

SUM: Add Up Values

SUM() adds up all values from a numeric column.

Total sales
SELECT SUM(order_total) FROM client_orders;

This returns the total amount from all orders.

Note: SUM() works only with numeric types such as INT or REAL.

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