我使用portgres 我有这个运行成功的查询。
SELECT count(distinct(salary.id)) AS nbr
FROM salary salary
WHERE salary.status ='P'
AND (salary.date_jc_salary is NULL and case priority_salary
WHEN 'N' THEN current_date > date_send_salary +interval '36' hour
WHEN 'U' THEN current_date > date_send_salary +interval '24' hour
ELSE current_date > date_send_salary +interval '36' hour end
OR (salary.date_jc_salary is NOT NULL
AND to_char(current_date , 'yyyy/MM/dd') >= to_char(date_jc_salary , 'yyyy/MM/dd')
) )
我的问题是我想让子查询具有interval的值。
意思是进行此查询:
SELECT count(distinct(salary.id)) AS nbr
FROM salary salary
WHERE salary.status ='P'
AND (salary.date_jc_salary is NULL and case priority_salary
WHEN 'N' THEN current_date > date_send_salary +interval '36' hour
WHEN 'U' THEN current_date > date_send_salary +interval '24' hour
ELSE current_date > date_send_salary +interval '36' hour end
OR (salary.date_jc_salary is NOT NULL
and current_date > salary.date_jc_salary +interval select salary.date_jc_salary::date - now()::date day
) )
所以只改变这一行:
and current_date > salary.date_jc_salary +interval select salary.date_jc_salary::date - now()::date day
但我有这个错误:
syntax error at or near "select"
LINE 10: ...rrent_date > salary.date_jc_salary -interval select sal...
^
********** Error **********
ERROR: syntax error at or near "select"
SQL state: 42601
Character: 847
目标是将日期 date_jc_salary 添加为 date_jc_salary 与当前日期之间的差异