Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Unit 6 C1: Calculations, cleansing and mining

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

55 minutes

Which snack makes the most money?

The Oakfield Youth Club cafe is made up. It sells tea, biscuits and juice. The manager wants the total taken, the most expensive item and the best seller.

She does not want to add up 200 lines by hand. Then she finds the same person on the sign-up list twice. This lesson is about sums, tidying and finding patterns.

By the end of this lesson

Note

I can use calculations and data cleansing to get reliable answers from a table.

Key words

WordWhat it means
Calculationa sum the table does for you, such as a total
Data cleansingfinding and fixing or removing bad data
Duplicatea record that appears more than once
Data miningsearching large amounts of data for patterns
Patternsomething that happens again and again

The cells students fill in are left blank in this preview.

Starter: what you already know

Have a go

Starter: what you already know

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

A query can add up for you

A calculation works out a number from many records. SUM gives the total. AVG gives the average. MAX gives the largest. MIN gives the smallest. COUNT counts the records.

Add GROUP BY to do the sum once for each group, such as each item.

Try it: totals and averages

Code: sql
-- All figures are in pence. quantity is how many were sold.
SELECT COUNT(*) AS sales,
       SUM(price_pence * quantity) AS total_pence,
       ROUND(AVG(price_pence), 1) AS average_price,
       MAX(price_pence) AS dearest,
       MIN(price_pence) AS cheapest
FROM cafe_sales;

-- One total for each item.
SELECT item, SUM(quantity) AS sold, SUM(price_pence * quantity) AS pence_taken
FROM cafe_sales GROUP BY item ORDER BY pence_taken DESC;

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

10 more parts of this lesson are in the full lesson, which colleges teach from the Library. A college account gives your students all of it.