0
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)
4

1 回答 1

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)
于 2013-07-02T08:56:33.887 回答