【问题标题】:How to separate a table from others using a column as a parameter如何使用列作为参数将表与其他表分开
【发布时间】:2021-12-27 15:20:57
【问题描述】:

我有数百行的下表: table

我正在尝试将每一行分开并发送到以下表格:“过去 15 天的访问”、“过去 30 天的访问”和“超过 30 天未访问”。

根据“tbdlf fsimage accesstime”列中的日期,进行此分离并将其发送到相应的表。

我正在通过 Hue 文件浏览器查询编辑器执行此操作

【问题讨论】:

    标签: sql function date hive hue


    【解决方案1】:

    您可以计算日期差异并根据条件使用multi-insert将数据插入到不同的表中:

    with src as (
    select t.* --list all columns which you need to insert
           --calculate category depending on difference in days
           case when datediff(current_date,to_date(accesstime))> 30 then 'not accessed for more than 30 days'
                when datediff(current_date,to_date(accesstime))> 15 then 'access in the last 30 days'
                when datediff(current_date,to_date(accesstime))<= 15 then 'access in the last 15 days'      
            end as category
      from tbdlf_fsimage t 
    )
    
    insert into table not_accessed_for_more_than_30_days
    select --list columns here
     from src 
     where category='not accessed for more than 30 days'
    
    insert into table access_in_the_last_30_days
    select --list columns here
     from src 
     where category='access in the last 30 days'
    
    insert into table access_in_the_last_15_days
    select --list columns here
     from src 
     where category='access in the last 15 days'
    ; --end of multi-insert
    

    【讨论】:

      猜你喜欢
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 2014-03-03
      • 2016-08-18
      • 2020-07-14
      • 1970-01-01
      相关资源
      最近更新 更多