Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
(revised previous post)I have this table:DATE --- SEVERITY --- BACKLOGdate1 --- 1 -------- 23date1 --- 2 -------- 34date1 --- 3 -------- 55date1 --- 4 -------- 66Instead 4 rows, I want 1 row with everything combinedex.DATE ---- SEV_1 ---- SEV_2 ---- SEV_3--- SEV_4date 1----23 ------ 34 --------55 ------66I want to do this is one SELECT StatmentAny ideas on where to start?Thanks!MichaelEdited by - kleinmi on 08/01/2002 11:04:28
Page47
Master Smack Fu Yak Hacker
2878 Posts
Posted - 2002-08-01 : 11:08:49
something ugly like this oughta work...
select date, (select backlog from kleinmi where date = k.date and severity = 1) as SEV_1, (select backlog from kleinmi where date = k.date and severity = 2) as SEV_2, (select backlog from kleinmi where date = k.date and severity = 3) as SEV_3, (select backlog from kleinmi where date = k.date and severity = 4) as SEV_4,from kleinmi kgroup by date
Or:SELECT date,Sum(CASE severity WHEN 1 THEN backlog END) as SEV_1,Sum(CASE severity WHEN 2 THEN backlog END) as SEV_2,Sum(CASE severity WHEN 3 THEN backlog END) as SEV_3,Sum(CASE severity WHEN 4 THEN backlog END) as SEV_4,FROM kleinmiGROUP BY date