Please help. It is necessary to make a sample and in the context of the day to produce a sum of unique values, first by one field, then by the second.

Grouping is suitable for date only. It turns out the sum of all duplicate values, and you only need a unique channel and src .

 SELECT SUBSTRING(calldate, 1, 10), COUNT(channel), COUNT(src), ROUND(SUM(billsec)/60, 0), ROUND(SUM(duration)/60, 0) FROM $userstable WHERE (channel LIKE '%SIP/iFree%') AND (SUBSTRING(calldate, 1, 10) BETWEEN '2011-10-01' AND '2011-10-30') AND (disposition LIKE 'ANSWERED') GROUP BY SUBSTRING(calldate, 1, 10) DESC"; 

    1 answer 1

    Use distinct .