我正面臨一個問題。我正在創建一個像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這裏即表4至表5
有沒有像下面
if(year=2016) then
with temp_table_2016 (select * from table4)
else with temp_table_2016 (select * from table6)
任何事情
這樣在單個查詢中,我可以用temp_table_2016替換table4或table5,根據條件它將從所需表中獲取數據。
該解決方案將取決於你所使用的數據庫。 –
你在四個不同的數據庫系統中面臨這個問題? – user272735
我現在面臨的DB2 – Rams