Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regrouping problem

Status
Not open for further replies.

jflo

Programmer
Mar 13, 2001
44
CA
Here's the query I use to get all de ages from a table and count the number of people in each age group.

SELECT Viptari.Age, Count(Viptari.Age) AS CountAge
FROM Viptari
GROUP BY Viptari.Age;

This is pretty straight forward.

Now I want to regoup these age groups as follows

0 to 14
15 to 35
36 to 40
41 to 45
46 to 50
51 to 60
61 to 65
66 and up

Any ideas?
 
Nevermind, I've tried it and it didn't work the first time but here's how. It's still pretty obvious.

SELECT IIf([Age]>0 And [Age]<15,&quot;0-14&quot;,IIf([Age]>14 And [Age]<36,&quot;15-35&quot;,IIf([Age]>35 And [Age]<41,&quot;36-40&quot;,IIf([Age]>40 And [Age]<46,&quot;41-45&quot;,IIf([Age]>45 And [Age]<51,&quot;46-50&quot;,IIf([Age]>50 And [Age]<61,&quot;51-60&quot;,IIf([Age]>60 And [Age]<66,&quot;61-65&quot;,&quot;66 and up&quot;))))))) AS test, Count(Viptari.Age) AS CountAge
FROM Viptari
GROUP BY IIf([Age]>0 And [Age]<15,&quot;0-14&quot;,IIf([Age]>14 And [Age]<36,&quot;15-35&quot;,IIf([Age]>35 And [Age]<41,&quot;36-40&quot;,IIf([Age]>40 And [Age]<46,&quot;41-45&quot;,IIf([Age]>45 And [Age]<51,&quot;46-50&quot;,IIf([Age]>50 And [Age]<61,&quot;51-60&quot;,IIf([Age]>60 And [Age]<66,&quot;61-65&quot;,&quot;66 and up&quot;)))))));

Sorry I asked! I'm need to get some sleep or better drugs...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top