MYSQL sum() for distinct rows

Posted by makeee on Stack Overflow See other posts from Stack Overflow or by makeee
Published on 2010-03-12T22:20:56Z Indexed on 2010/03/12 22:47 UTC
Read the original article Hit count: 151

Filed under:
|

I'm looking for help using sum() in my SQL query (not posting full query since the scenario is fairly simple).

I have COUNT(DISTINCT conversions.id) in my query. I use DISTINCT because I'm doing "group by" for multiple columns and this ensures the same row is not counted more than once.

Now I want to add:

SUM(conversions.value) as conversion_value

The problem is that the "value" for each row is counted more than once (due to the multiple group bys)

I basically want to do SUM(conversions.value) for each DISTINCT conversions.id.

Is that possible?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sum