Oracle中如何用子查询/派生表统计GROUP BY结果的I_Count总和
Solution to Get Total Sum of I_Count
Alright, since you're aiming to retrieve only the total sum of I_Count (which comes out to 10 based on your grouped results) and you've already endorsed Gordon Linoff's approach, here's how to wrap your existing GROUP BY query into a derived table to achieve this:
SELECT SUM(I_Count) AS Total_I_Count FROM ( -- Your original GROUP BY query as a derived table SELECT I_Count, I_Number, I_Letter FROM table GROUP BY I_Count, I_Number, I_Letter ) AS GroupedResults;
How this works:
- The inner query is your original GROUP BY statement, which generates the grouped results you shared:
I_Count | I_Number | I_Letter
4 | 100 | A
5 | 101 | B
1 | 102 | C - The outer query takes this derived table (
GroupedResults) and uses theSUM()aggregate function on theI_Countcolumn, adding up 4 + 5 + 1 to get the total sum of 10. - Since your requirement is to only get this total, the outer query returns exactly that single value without any extra columns.
内容的提问来源于stack exchange,提问作者Joseph
相关产品推荐
相关产品推荐

