这个sql有点长,大家来看看
写了个查询,统计加班工时的,相信CSDN上有很多朋友都碰到过这样的问题,
就是觉得有点长了,有点麻烦,用的是VB+Seagate Crystal Reports ,每次都要5到10秒左右,大家讨论下,用什么方法简化下(版面有限,可能看起来有点费劲)
SELECT SEC,PNL,NAME,INDATE,WK,WK_USE,WK_EUSE,WK1,WK2,WK3,WK4,WK5,WK6,WK7,WK8,WK9,WK10,WK11,WK12 FROM
(SELECT B.SEC,B.PNL,B.NAME,B.INDATE,C.WK,
(SUM(A.WK_OVER)+SUM(A.WK_HOLIDAY)+SUM(CASE WHEN A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN A.IWEEK= '1 ' THEN A.WK_STAND ELSE 0 END ) ) AS WK_USE,C.WK-(SUM(A.WK_OVER)+SUM(A.WK_HOLIDAY)+SUM(CASE WHEN A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END ) ) AS WK_EUSE,
WK1=(SUM(CASE WHEN A.CAR_D BETWEEN '20070101 ' AND '20070131 ' AND A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070101 ' AND '20070131 ' THEN A.WK_OVER+A.WK_HOLIDAY ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070101 ' AND '20070131 ' AND A.IWEEK= '1 ' THEN A.WK_STAND ELSE 0 END )),
WK2=(SUM(CASE WHEN A.CAR_D BETWEEN '20070201 ' AND '20070231 ' AND A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070201 ' AND '20070231 ' THEN A.WK_OVER+A.WK_HOLIDAY ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070201 ' AND '20070231 ' AND A.IWEEK= '1 ' THEN A.WK_STAND ELSE 0 END )) ,
WK3=(SUM(CASE WHEN A.CAR_D BETWEEN '20070301 ' AND '20070331 ' AND A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070301 ' AND '20070331 ' THEN A.WK_OVER+A.WK_HOLIDAY ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070301 ' AND '20070331 ' AND A.IWEEK= '1 ' THEN A.WK_STAND ELSE 0 END )) ,
WK4=(SUM(CASE WHEN A.CAR_D BETWEEN '20070401 ' AND '20070431 ' AND A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070401 ' AND '20070431 ' THEN A.WK_OVER+A.WK_HOLIDAY ELSE 0 END )+SUM(CASE WHEN A.CAR_D BETWEEN '20070401 ' AND '20070431 ' AND A.IWEEK= '1 ' THEN A.WK_STAND ELSE 0 END )) ,
WK5=(SUM(CASE WHEN A.CAR_D BETWEEN '20070501 ' AND '20070531 ' AND A.IWEEK= '7 ' THEN A.WK_STAND ELSE 0 END )+SUM(CASE WHEN &