[Solved] Mysql query – how to do this? [closed]


Try –

SELECT id,
       SUM( DISTINCT ss ) AS "Sum (ss)"
FROM tblData
GROUP BY id;

Note : Without GROUP BY SUM() will try to add up all values of ss, even with the DISTINCT qualifier. If you use GROUP BY but not DISTINCT then SUM() will add up all the values of ss for a particular value of id, even if they are repeated. Using DISTINCT in conjunction with GROUP BY here removes any repeated combinations before SUM() goes to work.

solved Mysql query – how to do this? [closed]