User:Samwilson/Blog/Calculating totals of joined tables

A database table  has a related table   listing what sized attachments it requires.

The task is to get a list of dates and total numbers of items and attachments (of two specific sizes):

Join
Simply joining the two gives this:

Pivot
The first thing to do is to pivot the attachments columns, selecting the two we want:

Sum
Then take the pivoted data and group it by date