我希望运行一个查询,该查询将返回客户请求表中的服务成本。请求表中有来自同一客户的多个请求。
我有查询:
SELECT REQUESTS.CUST, PRICE.COST FROM REQUESTS JOIN PRICE ON REQUESTS.SERV = PRICE.SERV ORDER BY REQUESTS.CUST ASC
这将返回服务成本,如下所示:
CUST|Cost 1001|10 1002|5 1002|4
我需要这个回来
Cust|Cost 1001|10 1002|9
答案 0 :(得分:0)
使用此
SELECT REQUESTS.CUST, SUM(PRICE.COST)
FROM REQUESTS
JOIN PRICE ON REQUESTS.SERV = PRICE.SERV
GROUP BY REQUESTS.CUST
ORDER BY REQUESTS.CUST ASC
答案 1 :(得分:0)
您需要对客户进行分组:
SELECT REQUESTS.CUST, sum(PRICE.COST)
FROM REQUESTS
JOIN PRICE ON REQUESTS.SERV = PRICE.SERV
GROUP BY REQUESTS.CUST
ORDER BY REQUESTS.CUST ASC