GreenPlum之生成月份字典表

--生成月份字典表
drop table if exists monthmapping;
create table monthmapping as 
select cast(to_char(onday,'yyyy-mm')||'-01' as char(10)) monthid,onday from (
select cast('2001-01-01 00:00:00' as timestamp) + (c ||' day')::interval as onday from generate_series(0,10000) as tab(c))tb
where onday<='2028-12-31'
distributed by(monthid,onday);

--當前時間加1年
SELECT now()::timestamp + '1 year';  

--當前時間加一個月
SELECT now()::timestamp + '1 month';  

--當前時間加一天
SELECT now()::timestamp + '1 day';  

--當前時間加一個小時
SELECT now()::timestamp + '1 hour';  

--當前時間加一分鐘
SELECT now()::timestamp + '1 min';  

--當前時間加一秒鐘
SELECT now()::timestamp + '1 sec';  

--當前時間加1年1月1天1時1分1秒
select now()::timestamp + '1 year 1 month 1 day 1 hour 1 min 1 sec'; 
 
--把columnname字段轉換成天然後相加
SELECT now()::timestamp + (columnname || ' day')::interval FROM tablename

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章