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:

enter image description here

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:

enter image description here

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:

enter image description here

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

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -