我有一张表,其中包含员工的每日总计和开始日期,我需要回顾 3 个月以查看员工工作了多少天。
这是我的sql查询:
SELECT
EMPNO,
CONVERT(VARCHAR(10), STARTDATE,101),
ROW_NUMBER() OVER (ORDER BY PERSONNUM) AS 'ROWCOUNT'
FROM EMPLOYEE
WHERE STARTDATE BETWENN DATEADD(month, -3, GETDATE()) and GETDATE()
GROUP BY EMPNO,STARTDATE
ORDER BY EMPNO
结果
EMPNO STARTDATE ROWCOUNT
TEST108 09/13/2013 1
TEST108 09/16/2013 2
TEST108 09/17/2013 3
TEST108 09/19/2013 4
TEST109 09/04/2013 5
TEST109 09/05/2013 6
TEST109 09/06/2013 7
TEST110 09/03/2013 9
TEST110 09/04/2013 10
TEST110 09/05/2013 11
期望的结果
EMPNO ROWCOUNT
TEST108 4
TEST109 3
TEST110 3
谢谢,