postgresql如果否则选择查询

时间:2015-08-26 02:49:45

标签: sql postgresql

我正在尝试进行首先进行比较的查询 第一个条件是比较 现在和 获取视图的最大年份view_delinquency_allquarter 然后,它将执行第一个查询 否则第二个查询

BEGIN
IF 
    select max(ctaxyear) as ctaxyear,
        (select cast ( (SELECT EXTRACT(QUARTER FROM TIMESTAMP 'now()'))  as int ) as yearnow) as yearnow
    from view_delinquency_allquarter 
    where ctaxyear > year_next
THEN
   select * from view_delinquency_allquarter;
ELSE 
   select * from view_delinquency;
END IF;
END

1 个答案:

答案 0 :(得分:0)

有很多answers以及documentation使用declare var然后分配var := (your query result)