Oracle Statement用于将计算列与另一列求和

时间:2014-01-15 20:48:17

标签: sql oracle

我正在尝试为公司添加所有延期价格。 而不是我的结果

Company_1 2000
Company_1 2000
Company_1 1000
Company_2 2000
Company_2 1000

我想看看

Company_1 5000
Company_2 3000

这是我目前的陈述。

SELECT COMPANIES.COMPANY_NAME, 
       INVC_HEADER.INVOICE_DATE, 
       (INVC_DETAIL.QTY_SHIP * INVC_DETAIL.UNIT_PRICE) as Ext_Price
  FROM ( INVC_DETAIL INVC_DETAIL 
 INNER JOIN INVC_HEADER INVC_HEADER 
    ON INVC_DETAIL.INH_AUTO_KEY = INVC_HEADER.INH_AUTO_KEY ) 
 INNER JOIN COMPANIES COMPANIES 
    ON INVC_HEADER.CMP_AUTO_KEY=COMPANIES.CMP_AUTO_KEY
 ORDER BY COMPANIES.COMPANY_NAME, INVC_HEADER.INVOICE_DATE DESC

1 个答案:

答案 0 :(得分:3)

您可以SUM找到您要查找的值GROUP BY公司名称

SELECT COMPANIES.COMPANY_NAME, 
        SUM(INVC_DETAIL.QTY_SHIP * INVC_DETAIL.UNIT_PRICE) as SumExt_Price
FROM   (INVC_DETAIL INVC_DETAIL INNER JOIN INVC_HEADER INVC_HEADER ON INVC_DETAIL.INH_AUTO_KEY=INVC_HEADER.INH_AUTO_KEY) 
        INNER JOIN COMPANIES COMPANIES ON INVC_HEADER.CMP_AUTO_KEY=COMPANIES.CMP_AUTO_KEY
GROUP BY COMPANIES.COMPANY_NAME