显示每周特定项目ID sql的小时数

时间:2016-07-25 11:05:50

标签: sql oracle

我有这样的表:

enter image description here

现在我想查看每个项目每周的小时总和。我如何查询。

我尝试了查询

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;

但是每个星期仍然是单独的行。不知道怎么做

1 个答案:

答案 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