Postgresql - 只执行某些 IF 语句

Postgresql - execute only certain IF statements

我想通过使用 UNION 来汇总一些查询的结果。但是我只想执行一些查询...在下面的示例中,('Daily','Yearly') 部分将自动填写。

大致如下:

(if 'Daily' in ('Daily','Yearly') then
my first query goes here...
end if)
UNION ALL
(if 'Monthly' in ('Daily','Yearly') then
my second query goes here...
end if)
UNION ALL
(if 'Yearly' in ('Daily','Yearly') then
my third query goes here...
end if)

在此示例中,第二个查询的结果不应出现在输出中。

附带说明:我已经有了 3 个工作查询,我缺少的是如何动态执行它们并将它们放在一起输出。

尝试将这些条件放在适当的“Where”部分。如果不满足文字条件,引擎必须跳过查询。

my first query goes here...
Where 'Daily' in ('Daily','Yearly')
UNION ALL
my second query goes here...
Where 'Monthly' in ('Daily','Yearly')
UNION ALL
my third query goes here...
Where 'Yearly' in ('Daily','Yearly')