I have the following script of 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 value "overdue", how can I do this?
Edit: Actually, I'm going to need more than this, I'm going to need to return 'overdue', 'win today' and 'overcoming', I already know I'll have to use CASE WHEN
, and I tried this 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 it came with NULL
.
Result
id_crecpa id_crecpa descricao diabase dt_emissao dt_vencto venc
--------- --------- ----------- ------- ---------- ---------- --------
87 87 Mensalidade 10 2018-01-12 2018-01-10 (NULL)