我目前正在使用下面的查询来收集2个日期之间的ER_read表的总数。这很好,但我需要将这些结果分成每周的部分,例如10月的第一周= 40(我认为)。是否有一个函数在MsSQL或PHP做到这一点,我将如何使用它?
SELECT SUM(ER_read) as total
FROM tblEread
WHERE ER_ID='$sensor'
AND MONTH(ER_date) >= '$firstMonth'
AND MONTH(ER_date) <= '$lastMonth'
AND YEAR(ER_date) = '$year'
GROUP BY ER_ID;
感谢您的帮助
从mySQL到MSSQL的标记如下:
在MS SQL Server 2005中获取周数?
https://stackoverflow.com/search?q=week +数量+ sql +服务器
select (datepart (dd,‘2008-10-08’)1)/7 + 1