2
I have the following query:
SELECT u.nome, u.email, u.login, u.data_cadastro, COUNT(*) AS qtd
FROM patrocinadores AS p
LEFT JOIN anuncios AS a ON a.id_user = p.id_user
INNER JOIN usuarios AS u ON u.id = p.id_user
WHERE p.id_patrocinador = '1' GROUP BY a.id_user
She pulls all the records that were sponsored by ID 1
. And it also returns me how many ads each sponsored registration has.
This command works perfectly, only I need to pull only the amount of active ads, that is, only when the column expira > time()
.
When I leave the query thus, with the WHERE a.expira > '...'
,
SELECT u.nome, u.email, u.login, u.data_cadastro, COUNT(*) AS qtd
FROM patrocinadores AS p
LEFT JOIN anuncios AS a ON a.id_user = p.id_user
INNER JOIN usuarios AS u ON u.id = p.id_user
WHERE p.id_patrocinador = '1' AND a.expira > '1449365367' GROUP BY a.id_user
she only returns to me the records in which a.expira
is longer than the current time. I want it to return all, but if the column time is less than the current time then it counts as 0 that record.
I just want to make a system that counts how many advertisements the accounts are from the sponsor 1
has assets.
I think that’s the only solution:
SUM( IF( a.expira > 1449365367, 1, 0 ) )
– Bacco
@Bacco I believe your answer solved!!!! ... Put as answer and I choose as correct ;) ... Thank you for you and for Ricardo!
– Alisson Acioli