DISTINCT或GROUP BY语句没有删除重复项?

时间:2016-09-22 16:41:11

标签: sql oracle

我想要做的是将所有客户账单合并为一个,所以不是“鲸鱼市场”出现三次不同的值,我希望“鲸鱼市场有一个总价值,总数将是{{1 }}

我尝试使用25968.75DISTINCT来显示重复的值。

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;

2 个答案:

答案 0 :(得分:3)

您可能想要使用聚合函数:

SELECT CLIENTNAME AS "Client", SUM(HOURSWORKED*CHARGERATE) AS "Total Billable"
FROM EMPLOYEE
WHERE CLIENTNAME IS NOT NULL
GROUP BY CLIENTNAME
ORDER BY "Total Billable" DESC;

答案 1 :(得分:1)

你需要:

SELECT CLIENTNAME AS "Client", SUM(HOURSWORKED*CHARGERATE) AS "Total Billable"
FROM EMPLOYEE
WHERE CLIENTNAME IS NOT NULL
GROUP BY CLIENTNAME
ORDER BY "Total Billable" DESC;