每7天的总和SQL

时间:2016-09-08 09:06:36

标签: sql sql-server-2008

美好的一天。我试图按data7 days。请先检查我的脚本。

select Nip,sum(ro) achieve,FullName 
        from( 
            select a.Nip,b.FullName,
            DATEPART( wk, c.attendanceDate) week, 
            sum(
                case when DATEADD(MINUTE, -480, OutTime) <=InTime 
                then 0 
                else DATEDIFF(MINUTE, InTime, OutTime) - 480 end)/480 AS RO 
                from DinasHoDetail a 
                left join Employee b on a.Nip = b.Nip 
                left join DinasHoHeader d on a.KodeDinasHeader = d.KodeDinasHeader 
                left join attendance c on a.Nip =c.Nip and attendancedate 
                between d.startdate and d.enddate 
                where a.KodeDinasHeader = 'DN0000001' 
                group by a.Nip,b.FullName,DATEPART( wk, c.attendanceDate)
            ) q group by Nip ,FullName

我的查询得到了这个结果。

Nip     achieve FullName
1004385    4    RENDY SETIAWAN
从我的查询中可以看到

。数据按week分组。当我手动求和时,结果是正确的。

所以,我的问题是,如何使用7 days而不是week更改上述查询。抱歉我的英语不好。

0 个答案:

没有答案