0
Order_ID
=========
id price
A 10
A 10
B 20
B 20
C 30
C 30
D 40
D 40
Client
==================
Client Name id
1 ClientInc. A
1 ClientInc. A
1 ClientInc. B
1 ClientInc. B
1 ClientInc. C
1 ClientInc. C
1 ClientInc. D
1 ClientInc. D
我有我需要加入(Order_ID上和客戶端),並要總結由不同ORDER_ID價格,並創建下面的報告兩個表:SUM DISTINCT VALUE [加入
Desired Solution
========================
id Name Sum(Price)
1 ClientInc. 100
這是我使用當前查詢:
SELECT merchant,
name,
SUM(price)
FROM order_id a
JOIN client b
ON a.id = b.id
GROUP BY merchant, name
它是通過總結每ORDER_ID顯示下面的輸出,但問題是,我要總結一個獨特的命令ID:
Current Wrong Report
======================
id Name Sum(Price)
1 ClientInc. 200
如果同一個ID有兩個不同的價格,你希望結果是什麼? –
使用DISTINCT關鍵字 –
您正在使用哪個[DBMS](https://en.wikipedia.org/wiki/Database)? Postgres的?甲骨文? DB2?火鳥? –