ajsqlnoob
Starting Member
5 Posts |
Posted - 2014-10-08 : 15:59:30
|
I’m a SQL noob and hoping someone can help me with this. I’m trying to return data in a single row.Here’s what my table looks like:Employee #,Hours Type,Total Hours1234,Regular,401234,OT,81234,Regular,361234,OT,51234,Doubletime,51234,Doubletime,71234,OT,67777,Regular,87777,Regular,127777,Regular,257777,Overtime,87777,Doubletime,5I need the results of my query to total each hours type and group together:EmpNo,Sum Of Regular, Sum of Overtime,Sum of Doubletime1234,76,19,127777,45,8,5I don’t know how to get the data returned in a single row. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-10-08 : 16:33:56
|
[code]SELECT [Employee #], SUM( CASE WHEN [Hours Type] = 'Regular' THEN [Total Hours] ELSE 0 END) AS [Sum Of Regular], SUM( CASE WHEN [Hours Type] = 'OT' THEN [Total Hours] ELSE 0 END) AS [Sum Of Overtime], SUM( CASE WHEN [Hours Type] = 'Doubletime' THEN [Total Hours] ELSE 0 END) AS [Sum Of Doubletime]FROM YourTableGROUP BY [Employee #][/code] |
|
|