我有一个按字段描述分组的查询。(总共有 9 个描述。)我需要以某种方式将其中的 3 个描述组合成一组,总共有 7 个描述。我是 sql 查询的新手,所以到目前为止,除了 JOINS 和 WHERE 子句之外,我对任何事情都很迷茫。我很感激帮助。
SELECT serviceclass.description, DATEPART(Year, meterread.readdate) AS Year, DATEPART(Month, meterread.readdate) AS Month, SUM(meterread.consumption)
AS Consumption, COUNT(DISTINCT accountservice.account_id) AS Locations
FROM accountservice INNER JOIN
serviceclass ON accountservice.serviceclass_id = serviceclass.serviceclass_id INNER JOIN
meterread ON accountservice.accountservice_id = meterread.accountservice_id
WHERE (@Year = DATEPART(Year, meterread.readdate))
GROUP BY serviceclass.description, DATEPART(Year, meterread.readdate), DATEPART(Month,meterread.readdate)
ORDER BY Year, Month