我有數百行的下表: 表
我試圖將每一行分開并發送到下表:“過去 15 天的訪問”、“過去 30 天的訪問”和“超過 30 天未訪問”。
根據“tbdlf fsimage accesstime”列中出現的日期,進行此分離并將其發送到相應的表。
我是通過 Hue File Browser Query Editors 做的
uj5u.com熱心網友回復:
您可以計算日期差異并使用 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/357996.html
下一篇:這是將x列印n次的正確代碼嗎?
