我有这样的表:
现在我想查看每个项目每周的小时总和。我如何查询。
我尝试了查询
select CurrentData.STATUS,
sum(CurrentData.HOURS), CurrentData.WEEKS
from CURRENT_DATA CurrentData
group by currentData.HOURS, CurrentData.STATUS, CurrentData.WEEKS, CurrentData.PROJECT_ID
having currentData.WEEKS = CurrentData.WEEKS
order by CurrentData.WEEKS;
但是每个星期仍然是单独的行。不知道怎么做
答案 0 :(得分:1)
不要在分组中使用HOURS。它们在组函数SUM中:
SELECT PROJECT_ID, STATUS, YEARS, WEEKS, SUM (CurrentData.HOURS)
FROM CURRENT_DATA
GROUP BY PROJECT_ID, STATUS, Years, WEEKS
ORDER BY Years, WEEKS
有条款中的内容。这总是如此。你想要一个星期和一年吗?你可以摆脱" CurrentData。"。您只有一个表,并且您不需要此表的别名。
此处筛选2016年,并汇总所有项目ID:
SELECT STATUS, WEEKS, SUM (CurrentData.HOURS)
FROM CURRENT_DATA
WHERE Years = 2016
GROUP BY STATUS, WEEKS
ORDER BY WEEKS