Select dates

3

I need to make a select that brings me instances that the start date of a license is less than 3 years from an employee's date of admission

Below is an 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');
    
asked by anonymous 02.12.2015 / 13:35

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');
    
02.12.2015 / 13:48
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');
    
02.12.2015 / 17:45