I have a table such as this
ID | cid |lightness | darkness | color
------|-------|-------------|--------------|---------
1 | 5 |10 | 20 | green
2 | 5 |10 | 08 | green
3 | 5 |10 | 10 | green
4 | 5 |20 | 05 | green
5 | 8 |10 | 20 | red
6 | 8 |10 | 16 | red
7 | 8 |33 | 20 | red
8 | 5 |10 | 10 | green
I want to find out the following:
- Count of records where color has lightness 10
- Count of records where color has darkness 20
So the output should be
Color | lightness | darkness | Total
---------|-------------|------------|---------
green | 4 | 1 | 5
red | 2 | 2 | 4
Total | 6 | 3 | 9
I’ve tried the query below but it doesn’t bring the correct results.
Select color, sum(lightness), sum(darkness)
from colortable
where cid in (5,8)
and (lightness = 10 or darkness = 20)
Group by color;
Save the following SQL as a new query, qryBaseCounts:
Then you can use qryBaseCounts in a UNION query:
This is the Access 2007 output from that second query using your sample data for colortable: