2014-06-26 88 views
0

我想結合這兩個語句,嘗試了很多在線搜索,但我只是flumoxed和嘗試各種組合似乎不工作(在Toad for Oracle)。試圖結合2選擇語句

幫助! (聲明一次做2到完成)

聲明1

select * 
from climate_trends.CT05_baseline_values 
    inner join climate_trends.CT03_grid_boxes 
     on climate_trends.CT05_baseline_values.location_id 
      = 
      climate_trends.CT03_grid_boxes.grid_box 

聲明2

select * 
from climate_trends.CT05_baseline_values 
where averaging_period_id in ('Spr','Sum','Aut','Win') 
     and climate_variable_id in('MeanTemp') 
     and location_type_id = 'Box' 
     and baseline_period = '1981-2010'; 

我現在已經添加了真正的價值,如果這使得更好的感覺?試圖讓一個單一的表,其中CT03保存空間參考我需要讓加盟...

+3

編輯您的問題,包括樣本數據和預期的結果。 –

+0

您想對查詢2的結果集執行查詢1嗎?帶有'union all'的 – Azar

+1

? –

回答

0

我認爲你正在尋找一個UNION SELECT

select * from table5 
inner join table3 
on table5 = table3 
union 
select * from table5 
where column1 in ('A','B','C','D') 
    and column2 in('Variable1') 
    and column3 = 'Variable2' 
    and column4 = Variable3'; 
0
select * 
from table3 
join (select * from table5 
where column1 in ('A','B','C','D') 
    and column2 in('Variable1') 
    and column3 = 'Variable2' 
    and column4 = Variable3') tabke5 on table5 = table3 
0

似乎與statement 2你試圖過濾基於statement 1的結果。

如果它是正確的,然後只需添加過濾條件從statement 2statement 1

select * 
from climate_trends.CT05_baseline_values as baselines 
    inner join climate_trends.CT03_grid_boxes as boxes 
     on baselines.location_id = boxes.grid_box 
where 
    baselines.averaging_period_id in ('Spr','Sum','Aut','Win') 
    and 
    baselines.climate_variable_id in('MeanTemp') 
    and 
    baselines.location_type_id = 'Box' 
    and 
    baselines.baseline_period = '1981-2010'