将SQL查询转换为Hive查询

时间:2019-07-12 11:36:48

标签: mysql hive hiveql

有人可以协助我将这个SQL查询转换为hive以获得相同的输出吗?

下面是查询

select count(email), 
       case substring_index(email,"@",-1) 
           when 'gmail.com'      then 'GMAIL' 
           when 'googlemail.com' then 'GMAIL' 
           when 'yahoo.com'      then 'YAHOO' 
           when 'ymail.com'      then 'YAHOO' 
            else 'OTHER' 
       END as DOMAIN  
   from DATA1 group by 2;

1 个答案:

答案 0 :(得分:0)

select count(email), 
       case split(email,'@')[1] 
           when 'gmail.com'      then 'GMAIL' 
           when 'googlemail.com' then 'GMAIL' 
           when 'yahoo.com'      then 'YAHOO' 
           when 'ymail.com'      then 'YAHOO' 
            else 'OTHER' 
       end as DOMAIN  
   from DATA1 
  group by 
    case substring_index(email,"@",-1) 
       when 'gmail.com'      then 'GMAIL' 
       when 'googlemail.com' then 'GMAIL' 
       when 'yahoo.com'      then 'YAHOO' 
       when 'ymail.com'      then 'YAHOO' 
       else 'OTHER' 
     end;

如果您希望group by 2工作,请阅读group by position syntax并相应地应用于您的配置单元版本。