時間差異(月):select (date '2003-08-15' - date '2003-01-01') month;
時間差異(天):select date '2003-08-15' - date '2003-01-01';
[@more@]
時間差異(秒):select ((time02 / 10000) * 3600 + (time02 / 100 mod 100) * 60 + (time02 mod 100)) -
((time01 / 10000) * 3600 + (time01 / 100 mod 100) * 60 + (time01 mod 100)) as time_diff
月份操作:select add_months(current_date, 3);
add_months(date, -2)
add_months(date '2002-01-31', 1);
本月第一天:select date - extract(day from date) + 1
上月最後一天:select date '2008-03-03' - extract(day from '2008-03-03')
decemal轉成time:select cast(cast(cast(timefld as format '99:99:99.99') as char(11)) as time(6)) from dbc.eventlog
依照當前時間得到timestamp: select cast(current_date as timestamp(2)) + ((current_time - time '00:00:00') hour to second);
上個星期五:select * from sys_calendar.calendar
where day_of_week = 6 --星期五
and calendar_date between date -6 and date; --上個星期
上週的今天:select * from sys_calendar.calendar where calendar_date = date-7
Teradata日期時間格式轉換問題
最近在入庫一大批資料,入了20多張表整整一天半時間,可謂是臉都僵了,然而就在處理日期型和時間型資料,通過自己的摸索,get到了一些套路,還是很開心的,趁請假還是好好總結一下吧!鑑於日期型資料date通常是用yyyy mm dd的格式進行儲存查詢,而時間型資料time在網上我也沒看到太多參考,但是注意...
TERADATA中函式的使用
cast函式 轉換函式,可以將字元型資料轉為日期型或資料型,將整型轉為浮點型,舉例如下 select cast 20140207 as date format yyyymmdd cast 07 as float cast 15 as float cast 18.987654 as dec 5,3 結...
TERADATA中函式的使用
cast函式 轉換函式,可以將字元型資料轉為日期型或資料型,將整型轉為浮點型,舉例如下 select cast 20140207 as date format yyyymmdd cast 07 as float cast 15 as float cast 18.987654 as dec 5,3 結...