スパークは、1行に複数の行をマージするSQL

使用される関数と定義

CONCAT_WS(SEP、[STR |配列(STR)] +) -文字列の連結09月によって分離返し。
例:

SELECT CONCAT_WS(」」、 'スパーク'、 'SQL');
スパークSQL

collect_set(expr)は -を収集戻るユニークな要素の集合。

例データ

ここに画像を挿入説明
私たちは、文字列は4列目は、1行に組み合わせる必要があります

select 
	Asset_a
	, concat_ws(',',collect_set(NT_Login)) as ntlogin 
from (
	select 
	Asset
	,Platform
	,UserOrBatch
	,NT_Login
	from eip_rewards_usage  
	where Platform='hercules' 
	and UserOrBatch='User'
	)
group by 1
order by 1 asc

まず、によってデータグループの制限を増やす必要があり、データ項目のグループ内でセパレータとして「」、一緒CONCAT_WSマージをNT_Loginをcollect_set

sparksql関数ドキュメント:
https://docs.databricks.com/spark/latest/spark-sql/language-manual/functions.html#concat_ws

リリース5元の記事 ウォンの賞賛2 ビュー171

おすすめ

転載: blog.csdn.net/DUTwangtaiyu/article/details/103661526