Distinct does not work

0

Good afternoon Personal, someone can tell me why this query does not work. Actually it works, but it brings the values in the wrong way (duplicating the department field), as if distinct did not work.

select distinct r.departamento, s.status, 
count(s.status) as quantidade from sac as s 
inner join responsaveis as r on s.id_sac = 
r.sac_id where r.departamento = 1 and s.status_sac = 1

    
asked by anonymous 23.08.2016 / 19:14

1 answer

1

The distinct grouping lines completely equal, which is not the case according to the results that were presented in the grid that you posted.

As you are using a grouping function (the count) the appropriate would be to use a clause "group by", grouping by the unique records that should be counted, this is the correct way to do this distinct, so I understood your query.

If my answer does not answer your need please edit your question and include more information about the database tables and their records so that you can help.

    
23.08.2016 / 19:20