配置单元中的多个union语句未给出正确的结果

时间:2018-03-24 21:26:14

标签: oracle hadoop hive

我正在尝试在Hive中运行简单转换,其中使用了多个union和union all语句。我从Oracle中提取数据。 Oracle查询:

SELECT t1.column1,                      
       t2.column2,                      
       t1.column3,                                              
  FROM table1 t1, table2 t2                     
  WHERE t1.column1 = t2.column1 and t1.column2 IN (3, 5, 8, 13) 

UNION ALL                       

  (SELECT t1.column1,                       
          t2.column2,                       
          t1.column3,                                               
    FROM table1 t1, table2 t2                       
    WHERE t1.column1 = t2.column1 and t1.column2 = 4    

   UNION                        

   SELECT t1.column1,                       
          t2.column2,                       
          t1.column3,                                               
     FROM table1 t1, table2 t2                          
     WHERE A.CAL = B.CAL and a.type = 4                         
           and (t1.column1 not like '%ABC%))

Hive查询:

SELECT t1.column1,                      
       t2.column2,                      
       t1.column3,                                              
  FROM table1 t1, table2 t2                     
  WHERE t1.column1 = t2.column1 and t1.column2 IN (3, 5, 8, 13) 

UNION ALL                       

  SELECT sub1.*
    from (SELECT t1.column1,                        
                 t2.column2,                        
                 t1.column3,                                                
            FROM table1 t1, table2 t2                       
            WHERE t1.column1 = t2.column1 and t1.column2 = 4    

          UNION                     

          SELECT t1.column1,                        
                 t2.column2,                        
                 t1.column3,                                                
            FROM table1 t1, table2 t2                           
            WHERE A.CAL = B.CAL and a.type = 4                      
            and (t1.column1 not like '%ABC%)) sub1;

理想情况下,两个查询都应该给我相同的结果,但我看到两个查询中的计数不匹配。我不明白我哪里错了?

0 个答案:

没有答案