Search⌘ K

Seeing the Big Picture: SUM, AVG, and COUNT

Learn how to count rows and take the sum and average of data.

Step 1: Start with a question

So far, you’ve been exploring individual rows—every employee, every record. Now let’s think bigger.

What if you asked: What’s the total salary cost for the company?

Instead of listing all employees, you want a single number, the total sum of all salaries.

Prompt: Write a SQL query that calculates the total of all salaries from the employees table.

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

Step 2: Run and observe

AI will likely produce:

MySQL
SELECT SUM(salary) AS "Total Salary Cost"
FROM employees;

Run it. You’ll see a single number.

Reflect:

  • One row now represents the whole dataset.

  • SUM() added up all ...