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 |
|
newber
Starting Member
1 Post |
Posted - 2007-07-06 : 10:15:52
|
| have a table with the following columsid, domain, statusdomain contains different major domains like aol.com,yahoo.com ect ectstatus has sent, bounce, deferI want to do a count for each of these per domain, in a nested querySo it would look like thisDomain | Sent | Bounce | Deferaol.com | 3000 | 34 | 34Any idea on how I would order my nested queries? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-06 : 10:21:57
|
[code]SELECT Domain, [Sent] = COUNT(CASE WHEN status = 'Sent' THEN 1 END), [Bounce] = COUNT(CASE WHEN status = 'Bounce' THEN 1 END), [Defer] = COUNT(CASE WHEN status = 'Defer' THEN 1 END)FROM yourtableGROUP BY Domain[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-06 : 23:31:39
|
| Also read about Cross-tab reports in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-06 : 23:32:44
|
quote: Originally posted by khtan
SELECT Domain, [Sent] = COUNT(CASE WHEN status = 'Sent' THEN 1 END), [Bounce] = COUNT(CASE WHEN status = 'Bounce' THEN 1 END), [Defer] = COUNT(CASE WHEN status = 'Defer' THEN 1 END)FROM yourtableGROUP BY Domain KH[spoiler]Time is always against us[/spoiler]
Do you have any tool that colours your code? MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-07 : 04:01:10
|
quote: Originally posted by khtan
quote: Do you have any tool that colours your code?
It is a macro in my editor courtesy of Ifor. See this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=85262 KH[spoiler]Time is always against us[/spoiler]
That seems coolI think the same code wont work in EXCELMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|