Re: SUM the DISTINCT values
On 1 Apr, 20:13, Shaq-Diesel <shik...@gmail.com> wrote:
> 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?
As Richard pointed out, you cannot sum strings. If you were storing
the amounts as numbers then the answer is trivial.
|