hive删除分区部分数据

时间:2025-02-17 07:23:59

hive表删除数据不能使用delete from table_name 的SQL语句,

一。删除分区部分数据

insert overwrite  table t_finance_tax_bill partition(importdate='20220218')
select 
    bill_id              ,
	apply_emp_id         ,
	bill_type_name       ,
	apply_emp_name       ,
	reimbursement_name   ,
	bill_apply_date      ,
	check_amount         ,
	appr_org_sfname      ,
	bill_beg_date        ,
	bill_end_date        ,
    bill_code	         ,
    jzpz	             ,
    jzpz_yz	             ,
    company_old_code	 ,
    account_period	     ,
    finance_number	     ,
    profit_center	     ,
    doc_date	         ,
    cart_head	         ,
    pstng_date           ,
	g0qykjkm             ,
    jzpz_tax	         ,
	jzpz_tax_yz	         
from 
   t_finance_tax_bill where importdate='20220218' and pstng_date='20220218';

注意:select后面不能使用*

二、删除分区全部数据

ALTER TABLE t_travel_analysis drop PARTITION (importdate='20220218')

三、删除多个分区数据

ALTER TABLE finance_tax_bill drop PARTITION (importdate>='20220901', importdate<='20221030') ;