试图结合2个选择语句

时间:2014-06-26 12:38:01

标签: sql oracle

我正在尝试将这两个语句结合起来,在网上尝试了很多搜索,但我只是在运行并尝试了各种组合似乎不起作用(在Toad for Oracle中)。

帮助!

声明1(完成一次声明2)

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 :(得分: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';

答案 1 :(得分: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

答案 2 :(得分:0)

似乎statement 2您尝试过滤statement 1后得到的基线。

如果它是正确的,那么只需将statement 2的过滤条件添加到statement 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'