I am trying to write 2 SQL queries. One returns a detailed list of stuff while the other summarizes the results. The problem is, I am forced to use 'distinct' in the first, detailed query but can't seem to use it in the summary one.
select distinct on (callid) * from calls where blah is blah
select count(1) , name from calls group by name
My detailed SQL is correct but my summary counts the duplicates so it is off. If I use the distinct in the summary SQL, it wants me to group by callid which kills what I'm trying to do.