以下查询为我提供了特定日期的最新日期/时间。
select *
from calendar c
where c.date= to_date('2018/03/09','yyyy/mm/dd')
and c.date >= all(select date from calendar c2 where c.date = c2.date)
如何将以上查询用作子查询,并将in子句作为参数传递给以下查询?
select * from (
/*above query inside and iterate over in param*/
)abc where abc.date in (to_date('2018/03/09','yyyy/mm/dd') ,to_date('2018/03/10','yyyy/mm/dd') )
答案 0 :(得分:0)
select *
from calendar c
where c.date in (to_date('2018/03/09','yyyy/mm/dd') ,to_date('2018/03/10','yyyy/mm/dd') )
and c.date >= all(select date from calendar c2 where c.date = c2.date)
尝试一下。
答案 1 :(得分:0)
我不知道我是否正确理解了你。这就是你想做的吗?
SELECT * FROM (
SELECT *
FROM calendar c
WHERE c.d_date= to_date('2018/03/09','yyyy/mm/dd')
AND c.d_date >= all(SELECT d_date FROM calendar c2 WHERE c.d_date = c2.d_date)
)abc WHERE abc.d_date IN (to_date('2018/03/09','yyyy/mm/dd') ,to_date('2018/03/10','yyyy/mm/dd') );
我将日期列的名称更改为d_date,因为它是保留字。
答案 2 :(得分:0)
对不起,我的意思是使用外部查询对子查询进行参数化,并且能够写出类似目的的东西
select *
from calendar c
where c.date >= all(select date from calendar c2 where c.date = c2.date)
and c.date in (to_date('2018/03/09','yyyy/mm/dd'),to_date('2018/03/10','yyyy/mm/dd') )