SELECT
DATEPART(YEAR, a.spdate) AS 'Year',
DATEPART(wk,a.spdate) AS 'WeekNo',
MONTH(a.spdate) As 'Month',
MIN(DATEADD(wk, DATEDIFF(wk,0,a.date), 0)) AS 'WeekDate',
SUM(COALESCE(a.value,0)) AS 'Value'
FROM patient a
JOIN dp account ON (a.id = d.id)
WHERE
a.id NOT IN (SELECT id FROM doctor)
GROUP BY DATEPART(YEAR,a.spdate),MONTH(a.spdate)
答案 0 :(得分:0)
试试这个
SELECT
DATEPART(YEAR, a.spdate) AS 'Year',
MONTH(a.spdate) As 'Month',
SUM(COALESCE(a.value,0)) AS 'Value'
FROM patient a
JOIN dp account ON (a.id = d.id)
WHERE
a.id NOT IN (SELECT id FROM doctor)
GROUP BY DATEPART(YEAR,a.spdate),MONTH(a.spdate)