1
I got the following script mysql:
SELECT con.id_crecpa,
con.id_crecpa,
con.descricao,
con.diabase,
con.dt_emissao,
con.dt_quitacao
FROM crecpa con
INNER JOIN pessoa pes ON con.id_pessoa = pes.id_pessoa
INNER JOIN plano_conta pla ON con.id_plano_conta = pla.id_plano_conta
WHERE con.id_empresa = 6
AND con.dt_vencto < CURDATE()
If the registration date is less than the current date, I want to return one more column with the "expired" value, how can I do this?
Edit: actually, I will need more than that, I will need to return 'defeated', 'wins today' and 'to win', I already know I will have to use the CASE WHEN
, and tried that way:
SELECT con.id_crecpa,
con.id_crecpa,
con.descricao,
con.diabase,
con.dt_emissao,
con.dt_vencto,
CASE con.diabase
WHEN con.dt_vencto < CURDATE() THEN 'vencido'
WHEN con.dt_vencto > CURDATE() THEN 'a vencer'
WHEN con.dt_vencto = CURDATE() THEN 'vence hoje'
END AS venc
FROM crecpa con
INNER JOIN pessoa pes ON con.id_pessoa = pes.id_pessoa
INNER JOIN plano_conta pla ON con.id_plano_conta = pla.id_plano_conta
WHERE con.id_empresa = 6
AND con.dt_vencto < CURDATE()
AND con.tipo = "Credito"
AND con.status = "Ativo"
but came NULL
.
Upshot
id_crecpa id_crecpa descricao diabase dt_emissao dt_vencto venc
--------- --------- ----------- ------- ---------- ---------- --------
87 87 Mensalidade 10 2018-01-12 2018-01-10 (NULL)
The column you have to always return... What changes is the value, look for the case when
– Rovann Linhalis
I updated the answer after your editing with some remarks. It is suggested that in the next questions already put the complete problem if possible, not to invalidate answers given.
– Bacco