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)
问问题
82 次