sql - DISTINCT OR GROUP BY statements not removing duplicates? -
what trying have client bills one, instead of "whale mart" coming 3 times different values wish "whale mart have 1 total value, total 25968.75
i tried using distinct
, group by
not show repeated values.
distinct
:
select distinct clientname "client", hoursworked*chargerate "total billable" employee clientname not null order "total billable" desc;
group by
:
select clientname "client", hoursworked*chargerate "total billable" employee clientname not null group clientname, hoursworked*chargerate order "total billable" desc;
both methods give same output:
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
you may want use aggregate function:
select clientname "client", sum(hoursworked*chargerate) "total billable" employee clientname not null group clientname order "total billable" desc;
Comments
Post a Comment