hive常見問題

2021-09-29 06:20:59 字數 1008 閱讀 7083

distinct用法:對select 後面所有欄位去重,並不能只對一列去重

(1) 當distinct應用到多個欄位的時候,distinct必須放在開頭,其應用的範圍是其後面的所有字段,而不只是緊挨著它的乙個字段,而且distinct只能放到所有欄位的前面

(2) distinct對null是不進行過濾的,即返回的結果中是包含null值的

(3) 聚合函式中的distinct,如 count( ) 會過濾掉為null 的項

group by用法:對group by 後面所有欄位去重,並不能只對一列去重。

select 去重欄位 from 表名 group

by 去重欄位

row_number() over()視窗函式

注意:row_number() over (partition by id order by time desc) 給每個id加一列按時間倒敘的rank值,取rank=1

select m.id,m.gender,m.age,m.rank

from

(select id,gender,age,row_number(

)over

(partition

by id order

by id) rank

from

temp

.control_201804to201806

where id!=

'na'

and gender!=

''or age!=

'') m

where m.rank=

1

使用group_concat函式
select group_concat(

distinct 去重欄位)

from 表名 group

by 去重欄位

hive 常見問題

原因 flume 匯入的orc 格式 建表語句儲存格式 textfile 不匹配導致 修改方案 建表語句和hdfs格式一致即可 修改表字段註解和表註解 alter table columns v2 modify column comment varchar 256 character set utf...

資料hive常見問題

1.mysql 匯入時問題轉碼,避免亂碼 mysql源有各種字符集 字元轉換 convert convert fieldname using binary using gbk as fieldname 防止換行 trim replace replace replace fieldname r n r...

HIVE架構以及HIVE常見問題

hive是執行在yarn上的,資料儲存在hdfs上。將sql語句轉換為mapreduce,當然hive本身做了一些優化,有些任務不會走mapreduce。hive其實就是把結構化的資料檔案對映到表中,hive表的元資料資訊儲存在關係型資料庫中,具體可以參見我的另一篇部落格,配置了mysql資料庫。s...