I need COUNT to return 0

Asked

Viewed 36 times

0

I have two tables with the following data:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

I want to rescue from the database all users and the amount of jobs they have performed. I was using the following SQL:

SELECT u.usuario, COUNT(t.id) AS '4' 
FROM usuario u LEFT JOIN trabalho t 
ON u.usuario = t.idUsuario 
WHERE t.realizado = 1 
AND t.dataTermino <= '2018-05-01' 
AND t.dataTermino >= '2018-04-01' 
GROUP BY u.usuario 

The problem is that if there is no work done for a user, the line is not returned, and I want to return the user name and 0.

  • 1

    The closure is similar, but I believe your case the "WHERE t.realizado = 1" only hinders, no?

  • Closed question, but follow mine solution

  • https://forum.imasters.com.br/topic/467840-resolver%C2%A0select-com-group-by-same-no-record-correspondent/? do=findComment&comment=1855090 see if it helps

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.