如何使用列作为参数将 table 与其他人分开

How to separate a table from others using a column as a parameter

我有以下 table 有数百行: table

我试图将每一行分开并发送到以下 tables:“最近 15 天的访问”、“最近 30 天的访问”和“超过 30 天未访问”天”。

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

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

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

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