Tommy Upton
Tommy Upton

Reputation: 13

SQL Combine Rows

I have a table that shows regular hours & overtime hours. Because of the way the old system exported the data, for many Pay Periods, I ended up with 2 records for each Pay Period - one for regular hours and another for overtime. Is there an easy way in SQL to add the overtime to same record with as the regular hours and then delete the overtime record?

See records 10 & ll.  Same pay period ending date and AccountingID

Upvotes: 0

Views: 55

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269463

You should be able to use aggregation:

select accountingid, payperiodenddate,
       sum(regularhours) as regularhours, sum(othours) as othours
from t
group by accountingid, payperiodenddate;

Upvotes: 1

Related Questions