2014-06-26 52 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'