SQL Query: Distinct Keyword fetches incorrect data
Posted on 2011-02-20
i have one table that has following columns.
Corresponding to IDs there is amount column.
Hence for ID 1, amount is 300, 2 is 400 and 3 is 500. I wish to sum the amount column for which i am using the distinct keyword so that the sum is 1200 and not 2400.
But here is the catch;
Say if ID is
and the values are 300, 400, 500 and 400. Hence the total should be 1600, but because i have used DISTINCT keyword for case1, the total comes to 1200.
How should i write my sql query so that both the case are satisfy?