Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how can i count a result

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-03 : 09:52:09
LEO writes "hi..........EVERYBODY

This is Leo Lin from Taiwan. I have a question, now I have a table which is about stuff data. I want get a result about their years old, I want to know how many peoply in 20-30 years old, 30-40 years old, 40-50 years old .......etc....

i want to know what statement I can use


Tell me please


Best Regard
Leo Lin"

Nazim
A custom title

1408 Posts

Posted - 2002-04-03 : 10:13:52
select (select count(*) from tablename where age between 20 and 30) as Age20-30,(select count(*) from tablename where age between 30 and 40) as Age30-40

HTH

--------------------------------------------------------------
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-03 : 11:02:35
This one is a little weird looking, but it works with one query:

SELECT Convert(varchar(3), (Age/10)*10) + '-' + Convert(varchar(3), ((Age+10)/10)*10) AS AgeGroup, Count(*) AS Total
FROM myTable
GROUP BY Convert(varchar(3), (Age/10)*10) + '-' + Convert(varchar(3), ((Age+10)/10)*10)


Go to Top of Page

lgraz
Starting Member

7 Posts

Posted - 2002-04-03 : 11:10:28
YO! Great looking solution!
Love that!

Graz
Go to Top of Page
   

- Advertisement -