我有一张桌子,显示常规时间和加班时间。由于旧系统导出数据的方式,在许多支付期间,我最终得到了每个支付期间的2条记录 - 一条用于常规小时,另一条用于加班。在SQL中是否有一种简单的方法可以将加班时间与常规时间一起添加到同一记录中,然后删除加班记录?
您应该能够使用聚合:
select accountingid, payperiodenddate,
sum(regularhours) as regularhours, sum(othours) as othours
from t
group by accountingid, payperiodenddate;