-2
I have the following table
ID| nome | Tipo
1 | Teste, João, Maria | Indicação
2 | Teste, Maria, José | Projeto de Lei
3 | Maria, José, João, Teste | Indicação
4 | Maria, João, José | Denúncia
I needed to list the types and count the amount of each of them that has a given name, ex:
Name: Test
- Indication (2)
- Draft Law (1)
- Complaint (0)
I built the code below but it didn’t work:
SELECT tipo,
COUNT(tipo) AS Qtd
FROM pessoas
WHERE FIND_IN_SET ("teste", nome)
ORDER BY COUNT(tipo) DESC
Take the example in practice: http://sqlfiddle.com/#! 9/0b41e8/1
That’s right, but what if I wanted to list also the guys who don’t have any amount?
– Frederico Moreira
You change the condition of your WHERE, because you specified the condition of the results, right?
– ElvisP
Check, resulting when there is no null, considering empty http://sqlfiddle.com/#! 9/d02feb2/1
– ElvisP
I think I’ll be able to adapt to what I need. Thanks for the help Eliseu
– Frederico Moreira