Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Distinct and Sum in SQL Select

Status
Not open for further replies.

dantheinfoman

Programmer
May 5, 2015
131
US
Hi All,

If I have a cursor that looks like this:
Screen_Shot_02-01-16_at_05.55_PM_pvlw6q.gif


What's the best way to get totals of hours,ttl_reg,ttl,ovt,ttloth by each Job+Employee combo.

So it may look like this:
Employee, Job, Hours, Ttl_reg, Ttl_ovt, Ttl_oth
1000, CL12345, 18.75, 0 , 0 , 0
1002, CLEAN#1, 5.75, 0 , 0 , 0
1001, SEC #2 , 16.75, 167.50, 0 , 0
1000, WORKSHP, 101.04, 422.20, 0 , 269.56

If you guys don't think this is an easy SQL statement away, then I can always just scan it and use "INSERT INTO" for another table. I just want to do things efficient, not the long way.

Thanks

Dan
 
Please try this simple query

Code:
SELECT Employee, Job, SUM(Hours) as Hours, SUM(Ttl_reg) as Ttl_reg, SUM(Ttl_ovt) as Ttl_ovt, SUM(Ttl_oth) as Ttl_oth GROUP BY Employee, Job FROM MyTable

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top