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

Preview

DA 1.15: Blending sources into one table

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

60 minutes

Did rain stop the buns?

A bakery has its sales. A weather site has the rain. The owner asks if rain hurts sales.

The answer sits across two tables. One writes dates day first. The other writes year first. Until they agree, nothing can be joined.

Key words

WordWhat it meansExample
BlendTo join data from different sources into one unified table.Sales plus weather
JoinA query step that matches rows from two tables on a shared field.Match on the day
Join keyThe field both tables share and the join uses.day
StandardiseTo write values the same way everywhere.All dates as year-month-day
Data typeThe kind of value a field holds, such as text or a date.Text or date
CompatibleAble to work together without conflict.Two date fields
QueryA question asked of a database.Show sales with rain
DatabaseA store of organised data a program can search.The sales table

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

By the end of this lesson

Note

I can prepare two sources, standardise them, blend them into one table and test the result.

Starter: what you already know

Have a go

Starter: what you already know

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.

Analyse the two sources

SourceJoin fieldIts type and formatFix needed
SalesdayText, day firstParse to a date
WeatherdayDate, year firstNone

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

Try it: standardise and blend

Code: duckdb
select strptime(s.day, '%d/%m/%Y')::date as day, s.total, w.rain_mm
from sales s
join weather w on w.day = strptime(s.day, '%d/%m/%Y')::date
order by day;

-- Try it: change join to left join and see which days have no weather.

Try it: test the outcome

Code: duckdb
-- Three sales days in. How many came out? Which has no weather?
select s.day, w.rain_mm
from sales s
left join weather w on w.day = strptime(s.day, '%d/%m/%Y')::date
where w.rain_mm is null;

The lesson goes on

3 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.