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.
| Author |
Topic |
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-09-25 : 07:01:36
|
| How to get the percentage for : user with age = 10 / total user?Select Count(User) From tableA (nolock) Where Id = 1 And Age = 10 --return 1Select Count(Id) FROM tableA (nolock) Where Id = 1--return 10 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-25 : 07:04:19
|
| [code]Select Count(case when Age = 10 then Id else null end)*1.0/Count(Id) AS [Age10Precentage] FROM tableA (nolock) Where Id = 1[/code] |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-09-25 : 07:11:11
|
| May I ask for what reason you store the age of a person instead of the date of birth? |
 |
|
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-09-25 : 10:13:41
|
quote: Originally posted by visakh16
Select Count(case when Age = 10 then Id else null end)*1.0/Count(Id) AS [Age10Precentage] FROM tableA (nolock) Where Id = 1
Great. Thanks. |
 |
|
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-09-25 : 10:14:47
|
quote: Originally posted by bjoerns May I ask for what reason you store the age of a person instead of the date of birth?
I just put an example scenario.. this is not the actual one.. |
 |
|
|
|
|
|