with as 的作用就是建立一张临时的中间表,可以提高hivesql的查询性能,另外要注意的是中间表只能使用一次。
例子:
with vod_pv as (
from gdfs.vod_asset_20200401 as a inner join gdfs.vod_20200401 as b on a.asset_id=b.asset_id
select b.current_user as current_user,b.client_type as client_type,b.region as region,a.asset_id as asset_id,a.asset_name as asset_name,b.provider_id as provider_id,b.category_id as category_id,b.product_info as product_info
)
select client_type,region,asset_id,asset_name,provider_id,category_id,product_info,count(asset_id) as pv_num from vod_pv group by client_type,region,asset_id,asset_name,provider_id,category_id,product_info;
可以直接在中间表进行查询
网友评论