ms access - How to find count of multiple records with different where conditions from same table -



ms access - How to find count of multiple records with different where conditions from same table -

i have table such this

id | cid |lightness | darkness | color ------|-------|-------------|--------------|--------- 1 | 5 |10 | 20 | greenish 2 | 5 |10 | 08 | greenish 3 | 5 |10 | 10 | greenish 4 | 5 |20 | 05 | greenish 5 | 8 |10 | 20 | reddish 6 | 8 |10 | 16 | reddish 7 | 8 |33 | 20 | reddish 8 | 5 |10 | 10 | greenish

i want find out following:

count of records color has lightness 10 count of records color has darkness 20

so output should be

color | lightness | darkness | total ---------|-------------|------------|--------- greenish | 4 | 1 | 5 reddish | 2 | 2 | 4 total | 6 | 3 | 9

i've tried query below doesn't bring right results.

select color, sum(lightness), sum(darkness) colortable cid in (5,8) , (lightness = 10 or darkness = 20) grouping color;

save next sql new query, qrybasecounts:

select sub.color, sub.light_10, sub.dark_20, light_10+dark_20 light_plus_dark [ select color, sum(iif(lightness=10,1,0)) light_10, sum(iif(darkness=20,1,0)) dark_20 colortable cid in (5,8) , (lightness=10 or darkness=20) grouping color ]. sub;

then can utilize qrybasecounts in union query:

select q1.color, q1.light_10 lightness, q1.dark_20 darkness, q1.light_plus_dark [total] qrybasecounts q1 union select "total", sum(q2.light_10) sum(q2.dark_20) sum(q2.light_plus_dark) qrybasecounts q2;

this access 2007 output sec query using sample info colortable:

color lightness darkness total greenish 4 1 5 reddish 2 2 4 total 6 3 9

ms-access

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -