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 2008 Forums
 Transact-SQL (2008)
 Please Help - SQl question

Author  Topic 

adiboy0420
Starting Member

10 Posts

Posted - 2012-07-11 : 00:19:56
Please Help

question: i need the > 71 to show on the bottom of the list, right now as you can see it is on top!!! so > 71 needs to after age 61-70 so how do i do that ?!? please help

this is my result

agegroup Number of people
> 71 1
30-40 122
41-50 106
51-60 41
61-70 20




-----------------


my code :

select a.Agegroup, SUM(a.[Number of People]) as 'Number of people'



from (


select DATEDIFF(year,birthdate,getdate())as Age, COUNT(DATEDIFF(year,birthdate,getdate())) as 'Number of People'
,

case

when

DATEDIFF(year,birthdate,getdate())between 30 and 40 then '30-40'

when DATEDIFF(year,birthdate,getdate()) between 41 and 50 then'41-50'

when DATEDIFF(year,birthdate,getdate()) between 51 and 60 then '51-60'

when DATEDIFF(year,birthdate,getdate()) between 61 and 70 then '61-70'

when DATEDIFF(year,birthdate,getdate()) between 71 and 80 then '> 71'

end as 'Agegroup'

from

HumanResources.Employee

group by DATEDIFF(year,birthdate,getdate())

)as A

group by a.Agegroup

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-11 : 04:08:20
[code]
ORDER BY
CASE WHEN [AgeGroup] = '> 71' THEN 1 ELSE 0 END ASC
, [AgeGroupp] ASC
[/code]
after the group by statement would probably work.

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

adiboy0420
Starting Member

10 Posts

Posted - 2012-07-11 : 12:08:06
That worked perfect. thankyou so much
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-11 : 12:31:03
welcome.

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page
   

- Advertisement -