hive 匯出資料之一列多行,轉為一行多列

2021-08-15 06:13:14 字數 3307 閱讀 6375

需求:提取資料

說明:原資料是一列多行,需要轉化為一行多列

待查詢表為:temp_05

hive> desc temp_05;

okdata_dt string

zhanghao string

booking_time_final string

sign string

hname string

channel string

min_price_weight string

time taken: 0.04 seconds, fetched: 7 row(s)

待查詢資料為:

hive>

> select

> booking_time_final,data_dt,min_price_weight

> from temp_05 where hname like'%兆龍%'

and booking_time_final like '%2018-02%'

and channel='5'

> ;

待查詢資料如圖:

需要提取的資料表頭如下:

預定日期

昨日**

前天**

2018-02-01

2018-02-02

2018-02-03

2018-02-04

可用提數 sql

select

booking_time_final,

concat_ws('',collect_set(if(data_dt='20180129',min_price_weight,''))) a,

concat_ws('',collect_set(if(data_dt='20180130',min_price_weight,''))) a2

from temp_05

where hname like

'%兆龍%'

and booking_time_final like

'%2018-02%'

and channel='5'

group

by booking_time_final ;

資料如圖:

以下為嘗試過程

hive>

> select

> if(data_dt='20180129'

and booking_time_final='2018-02-01',min_price_weight,'') a,

> if(data_dt='20180130'

and booking_time_final='2018-02-01',min_price_weight,'') a2

> from temp_05

> where hname like'%兆龍%'

and channel='5'

> ;

ok

資料如圖:

> where hname like'%兆龍%'

and channel='5'

> ;

資料如圖:

> where hname like'%兆龍%'

and booking_time_final like '%2018-02%'

and channel='5'

> ;

資料如圖:

> where hname like'%兆龍%'

and booking_time_final like '%2018-02%'

and channel='5'

> group

by booking_time_final

> ;

資料如圖:

sql多行轉為一列的合併

一 資料庫sql server列值鏈式合併 需求 原始表的資料的結構如圖1所示,把相同guid的code值生成乙個鏈式字串。圖1 目標 我們希望達到的效果如圖2所示,這裡的guid變成唯一的了,這行的記錄中包含了這個guid所對應的code字段值的鏈式字串。圖2 分析與實現 要實現圖1到圖2的轉變,...

sql多行轉為一列的合併問題

描述 將如下形式的資料按id欄位合併value欄位。id value 1 aa 1 bb 2 aaa 2 bbb 2 ccc 需要得到結果 id value 1 aa,bb 2 aaa,bbb,ccc 即 group by id,求 value 的和 字串相加 1 sql2000中只能用自定義的函式...

一列資料轉多行多列

一列資料轉多行多列 方法二 插入行列公式 公式解析 row 的功能是返回引用的行號 column 的功能是返回引用的列號 indirect函式 功能 返回文字字串所指定的引用 語法規則 indirect ref text,a1 ref text 單元格引用,該引用所指向的單元格中存放有對另一單元格的...