1
我想要做的是將所有的客戶賬單合併爲一個,因此,而不是「鯨魚市場」三次提出不同的價值,我希望「鯨魚市場有一個總價值,總數爲25968.75
DISTINCT OR GROUP BY語句不刪除重複項?
我嘗試使用DISTINCT
和GROUP BY
不顯示任何重複的值
DISTINCT
:
SELECT DISTINCT CLIENTNAME AS "Client", HOURSWORKED*CHARGERATE AS "Total Billable"
FROM EMPLOYEE
WHERE CLIENTNAME IS NOT NULL
ORDER BY "Total Billable" DESC;
GROUP BY
:
SELECT CLIENTNAME AS "Client", HOURSWORKED*CHARGERATE AS "Total Billable"
FROM EMPLOYEE
WHERE CLIENTNAME IS NOT NULL
GROUP BY CLIENTNAME, HOURSWORKED*CHARGERATE
ORDER BY "Total Billable" DESC;
種
兩種方法都給出相同的輸出:
Client Total Billable
------------------------- ---------------------------------------
Whale Mart 19868.75
Flitter 11271
Acme Corp. 9067.375
Flitter 8625
Astro Electric. 5500
Acme Corp. 4000
Lighting Unlimited 3675
Whale Mart 3200
ABM Systems 3106.75
Whale Mart 2900
ABC Logistics 2600
Acme Corp. 2475
Astro Electric 2312
Flitter 1845
ABM Systems 1005
ABC Logistics 900
Speedy Messengers 375
ABC Logistics 345
Durham Tiles 300
ABM Systems 160
20 rows selected