Office
(1)
Group.anyway
(1)

Query With Mutliple Criteria on Single Field

Asked By NPell
20-Jan-10 03:50 PM
Hi, i am trying to get a count of a certain criteria but in different
columns.

Its hard to explain, but assume i have a table which consists of...

A   550
B   600
C   20
A   100
C   75
B   120
D   390

Then in a query I am trying to have the result of:
Over 500            Over 100      Over 25      Under 25
A           1                        1
0                 0
B           1                        1
0                 0
C           0                        0
1                 1
D           0                        1
0                 0

The way i have done it was do 4 queries for that criteria, then try
and do a count from those queries.
im just getting myself in a mess.

any help would be greatly appreciated.

Hi NPell,this is an Italian News Group.anyway this query shows the result.

giorgio rancati replied to NPell
20-Jan-10 12:21 PM
Hi NPell,

this is an Italian News Group.
anyway this query shows the result.
----
SELECT Field1,
SUM(Iif(Field2>500,1,0)) AS [Over500],
SUM(Iif(Field2 Between 100 AND 499,1,0)) AS [Over100],
SUM(Iif(Field2 Between 25 AND 99,1,0)) AS [Over25],
SUM(Iif(Field2<25,1,0)) AS [Under25]
FROM Table1
GROUP BY Field1
----

bye
--
Giorgio Rancati
[Office Access MVP]
Post Question To EggHeadCafe