SQL里concat_ws()、collect_set()的使用

concat_ws(合并时的分隔符,合并字段1,字段2。。。)

collect_set(字段):根据某个字段分组后,把分在一组的数据合并在一起,默认分隔符','


eg:

select jzad,os_type,concat_ws(',',collect_set(host))
from
    (select  jzad,os_type,host,count(*),row_number() over(partition by jzad,os_type order by cast(count(*) as int) desc) rank
     from fengshang_1387ad_top10host_zqm group by jzad,os_type,host
    ) a where rank<=10
group by jzad,os_type

猜你喜欢

转载自blog.csdn.net/iboyman/article/details/79407915