1

我能够执行以下查询

select (current_date-interval '1' day) ,a,b from (select '1' as a, 2 as b) as t2;

但我无法用变量代替“1”。我尝试了以下方法但没有成功

select (current_date-interval b day) ,a,b from (select '1' as a, 2 as b) as t2;
select (current_date-interval a day) ,a,b from (select '1' as a, 2 as b) as t2;

我也尝试过铸造,但仍然没有结果。

4

1 回答 1

1

我找到了解决方案:

select (current_date-interval 1 day*b) ,a,b from (select '1' as a, 2 as b) as t2;
select (current_date-interval 1 day*cast(a as int)) ,a,b from (select '1' as a, 2 as b) as t2;

所以这个问题得到了回答:)

于 2013-04-29T07:40:09.587 回答