문제

I am able to do the following query

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

But I am not able to put variables in place of '1'. I have tried the following methods with no success

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;

I have also tried casting but still no result.

도움이 되었습니까?

해결책

I found a solution to this:

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;

So this question is answered :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top