我们正在将一些旧的Oracle内容转换为MS SQL Server,并且Oracle具有多参数子查询,我正在尝试找出如何在MS SQL Server中执行此操作。我对Oracle语法不是很熟悉,也很难弄清楚如何转换它。
原始where子句的相关部分是:
and (rate.tax_code, rate.effect_date) in
(select tax_code, max(effect_date)
from v_txtaxrate
where effect_date <= '10-JAN-14'
group by tax_code)
我尝试使其成为两个子查询:
and rate.tax_code in
(select tax_code
from v_txtaxrate
where effect_date <= '10-JAN-14'
group by tax_code)
and rate.effect_date in
(select max(effect_date)
from v_txtaxrate
where effect_date <= '10-JAN-14'
group by tax_code);
但结果表明这些并不相同。
我将使用“ EXISTS”代替“ IN”:
and exists (
select 1
from (select tax_code, max(effect_date) effect_date
from v_txtaxrate
where effect_date <= '10-JAN-14'
group by tax_code) a
where rate.tax_code = a.tax_code
and rate.effect_date = a.effect_date
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句