我正在Oracle 10g中创建一个View。有关我的数据的示例,请参见附图。我希望能够对具有相同ProjectCode和Month的所有记录执行SUM。我在下面的查询仍然显示了单独列出的每个ProjectCode的个别月份:
SELECT ProjectCode, ItemNumber, ItemCode, Type, SUM(Estimate), Month
FROM ProjectDetails
<bunch of INNER JOINS HERE>
WHERE ProjectDetails.ProjectCode=AllDetails.ProjectCode
GROUP BY ProjectCode, ItemNumber, ItemCode, Type, Estimate, Month;
答案 0 :(得分:2)
group by
你想看的东西。从select
和group by
:
SELECT ProjectCode, SUM(Estimate), Month
FROM ProjectDetails
<bunch of INNER JOINS HERE>
WHERE ProjectDetails.ProjectCode=AllDetails.ProjectCode
GROUP BY ProjectCode, Month;
编辑:
也许这就是你想要的:
SELECT ProjectCode, ItemNumber, ItemCode, Type, SUM(Estimate), Month
FROM ProjectDetails
<bunch of INNER JOINS HERE>
WHERE ProjectDetails.ProjectCode=AllDetails.ProjectCode
GROUP BY ProjectCode, ItemNumber, ItemCode, Type, Month;
注意:我所做的就是从estimate
删除group by
。
您还应该将连接条件放在from
子句中,而不是where
子句中。