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 |
|
waxdart23
Starting Member
33 Posts |
Posted - 2004-09-24 : 09:33:07
|
| I have a table which contains account numbers (account) and performances attended by the account holder (perf) within a season. So accounts can have multiple values of performances (because account holders can attend numerous performances) but each erformance can only have distinct accounts (because an account holder can only attend a performance once.I am trying to write a statement that will count the number of accounts that attended the various frequencies of performances. I.e. xxx accounts attended one performance, yyy attended 2 performances and zzz attended 3 performances etc?Can anyone help?ThanksP |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-09-24 : 09:37:57
|
it would help vastly if you gave us DDL and DML (create table stmts and insert stmts for sample data)but here goesSet ESP OnSelect Performances, cnt = count(*)From ( Select <accountNum>, performances=count(*) From <performanceHistory> Group By <accountNum> ) AGroup By PerformancesSet ESP Off Corey |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-09-24 : 09:38:37
|
| Assuming all rows in the table has both an account and a per, then how about this:SELECT account, COUNT(*)FROM MyTableGROUP BY accountRaymond |
 |
|
|
waxdart23
Starting Member
33 Posts |
Posted - 2004-10-06 : 09:13:48
|
| Seventhnight's was what I was after but raymondpeacock's was handy for something else I was doing with ther same data!So thanks to both of you for your help.ThanksP |
 |
|
|
|
|
|