【发布时间】:2016-11-10 14:08:14
【问题描述】:
我面临一个问题。我正在创建一个类似 Temp_district 的过程。
其中有一个要求,例如基于某些条件,我们必须更改连接表。
like if(year=2016) then
select * from table1 a join table2 b on (a.id=b.id) join table3 c on (c.id=b.id) join table4 d on d.id=a.id
if(year<>2016) then
select * from table1 a join table2 b on (a.id=b.id) join table3 c on (c.id=b.id) join table5 e on d.id=a.id;
查询几乎相同,查询量太大,如果这里的年份不是 2016 年,即 table4 到 table5,则只有一个表发生变化
有没有像下面这样的东西
if(year=2016) then
with temp_table_2016 (select * from table4)
else with temp_table_2016 (select * from table6)
这样在单个查询中我可以用 temp_table_2016 替换 table4 或 table5,根据条件它会从所需表中获取数据。
【问题讨论】:
-
解决方案取决于您使用的数据库。
-
您在四个不同的数据库系统中面临这个问题?
-
我在 DB2 中遇到了问题
标签: db2