I have the following data from 2 tables Notes (left) and scans (right) :

Imagine the picker and packers were all varying, like you can have JOHN, JANE etc.
I need a query that outputs like so :
On a given date range :
Name - Picked (units) - Packed (units)
MASI - 15 - 21
JOHN - 21 - 32
etc.
I can’t figure out how to even start this, any tips will be helpful thanks.
Without a “worker” take that lists each Picker/Packer individually, I think you’d need something like this…
(This is actually just an algebraic re-arrangement of the answer that @RaphaëlAlthaus posted at the same time as me. Both use
UNIONto work out the Picker values and the Packer values separately. If you have separate indexes onscans.Pickerandscans.Packerthen I would expect mine MAY be slowest. If you don’t have those two indexes then I would expect mine to be fastest. I recommend creating the indexes and testing on a realtisic data set.)EDIT
Actually, what I would recommend is a change to scans table completely; normalise it.
pickerandpacker.roleandworker.This allows you to create simple indexes and simple queries.
You may initially baulk at the extra unecessary rows, but it will yield simpler queries, faster queries, better maintainability, increased flexibility, etc, etc.
In short, this normalisation may cost a little extra space, but it pays back dividends forever.