| Author |
Topic |
|
Shelly1
Starting Member
25 Posts |
Posted - 2009-05-06 : 06:23:19
|
I would like to count customer ages beetween 20 and 30, I can only work out how to search for 20+ELECT CustomerAge, COUNT(*) TotalCountFROM THISTWhere IncDate between '1 may 09' and '2 may 09'GROUP BY PatientAgeHAVING COUNT(*) >20ORDER BY COUNT(*) DESC Can anyone help!Thanks Mich |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-06 : 06:31:49
|
Please post your table DDL with sample data and the expected result.The query you posted is confusing. You have CustomerAge and PatientAge which is the correct column KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-05-06 : 06:33:12
|
| I can't see your query working as posted.You are grouping by patientAge but then referencing CustomerAge in the SELECT without an aggregate function.Post some sample data and table structure.You'll get a nice fast statement from someone in 5 mins if you do this.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-06 : 06:34:48
|
| SELECT CustomerAge, COUNT(*) TotalCountFROM THISTGROUP BY PatientAgeHAVING IncDate between '1 may 09' and '2 may 09'ORDER BY COUNT(*) DESCMalay |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-05-06 : 06:34:52
|
| having count(*)>20 filters out those customerages where count of records is greater than 20. Do you want to filter out basis count of customers, or customerage ? |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-05-06 : 06:39:03
|
quote: Originally posted by malaytech2008 SELECT CustomerAge, COUNT(*) TotalCountFROM THISTGROUP BY PatientAgeHAVING IncDate between '1 may 09' and '2 may 09'ORDER BY COUNT(*) DESCMalay
Why did you post this?Event with the S in SELECT it's still wrong.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-06 : 06:39:57
|
| SELECT CustomerAge, COUNT(*) TotalCountFROM THISTGROUP BY PatientAgeHAVING PatientAge between 20 and 30ORDER BY COUNT(*) DESCMalay |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-06 : 06:50:51
|
[code]SELECT PatientAge, COUNT(*) TotalCountFROM THISTWHERE PatientAge BETWEEN 20 AND 30GROUP BY PatientAgeORDER BY COUNT(*) DESC[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Shelly1
Starting Member
25 Posts |
Posted - 2009-05-06 : 09:09:19
|
| Hi Sorry for the confusing syntax, the last post worked - thanks very much.Mich |
 |
|
|
|