sql server - SQL Group By and window function -
i struggling little bit sql statement , hoping if willing point me in right direction.
below picture of table:
as can see here have column called 'state'. want group 'state' associated particular buildid , display them in column on sql output.
i close not quite there.
in next picture below example of statement have used try , achieve this:
as can see here, has done sum , added totaltime , created columns require. instead of grouping 1 record, has created 2 lines per buildid. 1 value 'running' state, record value state of 'break' , record contains value 0 on both states.
now want group 1 record each buildid. picture have added below:
the above image how want records displayed. problem have added [state] = running, know wrong using example. can see 'break' column has no value.
i hope makes sense , hoping if point me in right direction?
here example on sql fiddle http://sqlfiddle.com/#!3/7b6b9/2
thanks taking time read :)
have refined sql bit, here go:
select buildid,product, program, sum(case when state = 'running' cast(totaltime int) else 0 end) running , sum(case when state = 'break' cast(totaltime int) else 0 end) breakt line1log group buildid,product, program
please check sqlfiddle
not sure if missing :-), solution looks pretty straight forward. let me know.
Comments
Post a Comment