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 |
|
carvals
Starting Member
2 Posts |
Posted - 2007-07-24 : 18:56:46
|
| Hi,I'm developping an application and I've got some trouble with the database. I would like to retrieve data to build a graph.A sample of dataType1_______Type2 P1__________ A P2__________ BP3__________ A P1__________ A I would like a result like:Type1________ A ________ BP1 __________ 2 ________ 0 P2 __________ 0 ________ 1P3 __________ 1 ________ 0with this function I can create the first and the second column:SELECT Type1, COUNT(Type2) AS AFROM Table1 WHERE (Type2= 'A')GROUP BY Type1But I've got some trouble to create the third one... I tried subquery but doen't work with the "group by"... Please HELP!!!!Thanks.. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-24 : 19:03:10
|
[code]SELECT Type1, [A] = SUM(CASE WHEN Type2 = 'A' THEN 1 ELSE 0 END), [B] = SUM(CASE WHEN Type2 = 'B' THEN 1 ELSE 0 END)FROM Table1GROUP BY Type1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
carvals
Starting Member
2 Posts |
Posted - 2007-07-24 : 19:16:58
|
| Hi KhTanGreat!!! thanks!To easy for you I guess... |
 |
|
|
|
|
|