Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 04-03-2008, 06:49 PM
Luuk
 
Posts: n/a
Default Re: SUM the DISTINCT values

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:26 PM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.