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 |
|
kmorgan26
Starting Member
2 Posts |
Posted - 2010-04-07 : 12:27:19
|
| I have three tables: Table1 and Table2 and Table 3Table 3 is a "status" table. 1=open, 2=working, 3=closedSELECT T1.t1ID, T1.Title, COUNT(T2.t3ID) as myCountFROM T1 LEFT OUTER JOINT2 ON T1.t1ID = T2.t1IDGROUP BY t1.t1ID, t1.TitleThis displays as such:1 | title 1 | 42 | title 2 | 23 | title 3 | 04 | title 4 | 1What I want to do is add a condition to the third column. I only want the items counted in the third column if they are NOT closed (ID of 3)Thanks in advance for the help! |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-07 : 12:29:31
|
SELECT T1.t1ID, T1.Title, --COUNT(T2.t3ID) as myCountsum(case when T2.t3ID = 3 then 0 else 1 end) as myCountFROM T1 LEFT OUTER JOINT2 ON T1.t1ID = T2.t1IDGROUP BY t1.t1ID, t1.Title No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
kmorgan26
Starting Member
2 Posts |
Posted - 2010-04-07 : 12:33:09
|
| Thanks webfred! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-07 : 12:37:17
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|