我正在尝试为公司添加所有延期价格。 而不是我的结果
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
答案 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