1. 程式人生 > >hive 三種去重方式

hive 三種去重方式

在hive資料清洗這裡總結三種常用的去重方式

1.distinct

2.group by

3.row_number()

例項:

SELECT tel, link_name, certificate_no, certificate_type, modify_time
  FROM order_info
 WHERE deleted = 'F'
   AND pay_status = 'payed'
   AND create_time >= to_date('2017-04-23', 'yyyy-MM-dd')
   AND create_time < to_date('2017-04-24', 'yyyy-MM-dd')
   AND row_number() over(PARTITION BY tel ORDER BY tel DESC) = 1

上面SQL對某一欄位(tel)排序後分區去重,這樣避免了其對不相干欄位的資料干擾,影響資料處理的效率

推薦方法三