Select of dates

Asked

Viewed 46 times

3

I need to make a select that brings me occurrences that the initial date of a leave is less than 3 years from the date of an employee’s admission

Follow below excerpt from my code.

SELECT *
FROM
    jmh_licenca l
    INNER JOIN
    jmh_servidor s on l.lic_ser_id = s.ser_id
    INNER JOIN
    jmh_doenca d ON l.doe_id = d.doe_id 
WHERE
    l.lic_data_inicial BETWEEN '2012-08-01' AND '2015-08-01' AND
    l.lic_data_inicial **< (3anos)** s.ser_data_admissao AND
    tip_lic_id in ('9', '12');
  • AND year(l.lic_initialdata_) < 3 year must relate to the date of admission of each official.

  • See this link ... Here

2 answers

1

Try the following code:

SELECT * FROM jmh_licenca l
INNER JOIN jmh_servidor s on l.lic_ser_id = s.ser_id 
INNER JOIN jmh_doenca d ON l.doe_id = d.doe_id 
WHERE l.lic_data_inicial
BETWEEN '2012-08-01' AND '2015-08-01' 
AND l.lic_data_inicial < s.ser_data_admissao - INTERVAL '3 Year' AND tip_lic_id in ('9', '12');

0

select *
from
    jmh_licenca l
    inner join
    jmh_servidor s on l.lic_ser_id = s.ser_id
    inner join
    jmh_doenca d on l.doe_id = d.doe_id 
where
    l.lic_data_inicial between '2012-08-01' and '2015-08-01' and
    l.lic_data_inicial::timestamp - s.ser_data_admissao < interval '3 years' and
    tip_lic_id in ('9', '12');

Browser other questions tagged

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