hive的muti group by

使用muti group by之前:
echo "订购 下载 试听 搜索 pv uv :=============================================  "
 hive -e "use platform;
     select ${group},sum(buy),sum(down),sum(listen),sum(search),sum(pv),count(distinct IMSI)  from(
   select ${group},IMSI,
case when action=1 then 1  else 0 end as buy,
case when action=2 then 1  else 0 end as down,
case when action=3 then 1  else 0 end as listen,
case when action=4 then 1  else 0 end as search,
case when (${pvcase}) then 1 else 0 end as pv
from T_FeedbackAccessday2 where ${case}
)middle group by ${group};"  | grep "2013-" >tmp.data


echo "流量:============================================= "
hive -e "use platform;
 select day,porttype,subporttype,'flow',sum(abs(yidong)), sum(abs(notyidong)) from(
select day,porttype,subporttype,
case when (UCASE(network) in('CTWAP','CTNET') and abs(FluxByte)<10485760) then FluxByte  else cast(0 as bigint) end as yidong,
case when (UCASE(network) not in('CTWAP','CTNET') and abs(FluxByte)<10485760) then FluxByte  else cast(0 as bigint) end as notyidong
from T_FeedbackAccessday2 where ${case} and (PortType !=5 OR subporttype!=4) OR (PortType =5  and subporttype =4  and ActionModule= 'actionFeedback')) middle
group by day,porttype,subporttype" | grep "2013-" >flow.data





使用后:
hive -e "use platform;
from T_FeedbackAccessday2
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='buy')
select porttype,subporttype,comefrom,'',sum(case when action=1 then 1  else 0 end) as buy  where ${case} 
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='down')
select porttype,subporttype,comefrom,'',sum(case when action=2 then 1  else 0 end) as buy  where ${case} 
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='listen')
select porttype,subporttype,comefrom,'',sum(case when action=3 then 1  else 0 end) as buy  where ${case} 
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='search')
select porttype,subporttype,comefrom,'',sum(case when action=4 then 1  else 0 end) as buy  where ${case} 
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='uv')
select porttype,subporttype,comefrom,'',count(distinct IMSI) as buy  where ${case} 
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='pv')
select porttype,subporttype,comefrom,'',sum(${pvcase}) as buy  where ${case}
group by ${group}
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='yidong')
select porttype,subporttype,'','',sum(${yidongcase}) as buy  where ${case}
group by porttype,subporttype
INSERT OVERWRITE TABLE result2 PARTITION(day='${day}',category='notyidong')
select porttype,subporttype,'','',sum(${notyidongcase}) as buy  where ${case}
group by porttype,subporttype;"




从我的这个使用场景来看,使用前后的运行时间是差不多的.

你可能感兴趣的:(hive)