![]() |
| |||
| Shaq-Diesel schreef: > On Apr 1, 4:17 pm, Luuk <L...@invalid.lan> wrote: >> Shaq-Diesel schreef: >> >> >> >>> I am trying to SUM only the DISTINCT rows from a particular column >>> from my database. >>> For example: >>> My database looks like this >>> ORDERID PRODUCT PRODUCTCOST ORDERTOTAL >>> 1 Xbox $400 >>> $600 >>> 1 Wii $200 >>> $600 >>> 2 Controller $30 >>> $75 >>> 2 Game $20 >>> $75 >>> 2 Cords $25 >>> $75 >>> What I want to do is find the total sale(so i want to SUM only the >>> DISTINCT ORDERID). In this case the answer would be $675. >>> So I tried without success: >>> SELECT DISTINCT(ORDERID), SUM(ORDERTOTAL) From tablename <-- no luck >>> Any ideas? >> SELECT DISTINCT(ORDERID), SUM(PRODUCTCOST) From tablename >> GROUP BY ORDERID >> >> -- >> Luuk > > Luuk, > > This does NOT work. Although it does yield an error, it does not yield > an answer to the question. What this returns is the sum of EACH unique > ORDERID. Not the total of ALL the distinct ORDERTOTAL. That was my > guess too... > > > i must have mis-read you question, but now Captain Paralytic already gave the right answer... or you yourself could start with the above, and find out yourself how to get the requested value.... i think you will get more satisfied if you find your own solution.. ? -- Luuk |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |