sql server - Is it possible to sum records from a column based on records from a different column? -


jobno     stepno  workcntr   hours 10342-63    10    cutting    1.95 10390-30    10    cutting    2.59 10390-32    10    cutting    3.45 10390-34    10    cutting    2.55 10390-34    10    cutting    1.82 

so have table above, here's code:

select distinct orderdet.jobno, orderdet.stepno, orderdet.workcntr, orderdet.hours orderdet; 

what i'd sum hours if job number same , have distinct filter out duplicate, ideally, table should this:

jobno     stepno  workcntr   hours 10342-63    10    cutting    1.95 10390-30    10    cutting    2.59 10390-32    10    cutting    3.45 10390-34    10    cutting    4.37 

any way this? using sql server 2012. in advance

this basic aggregation query using sum() , group by:

select jobno, stepno, workcntr, sum(hours) hours orderdet group jobno, stepno, workcntr 

Comments