sql 取自然年的方法

2021-09-25 22:48:16 字數 668 閱讀 7470

select nvl(sum(order_ticket_num),0)

from crs_order c

left join crs_order_contact cc

on c.id_order = cc.id_order

where cc.openid = #

and c.tm_update >

to_date((to_char(trunc(sysdate, 'year') - 1, 'yyyy') ||

'-12-31 23:59:59'),

'yyyy-mm-dd hh24:mi:ss')

and c.tm_update <= sysdate

and c.is_del = 0

and c.order_status != 10021030

and c.order_status != 10021040

and cc.is_del = 0

and c.product_type='10271010'

and c.source_code = #

用的oracle資料庫,以當前系統時間為引數,取表裡時間字段大於上一年12月31日23:59:59秒並且小於當前系統時間的值 就是自然年內的資料。  如果測試不通過,則麻煩校對一下 線上庫之間的系統時間 是否一致

php獲取自然周 自然月的處理

取得當前時間的上一周時間用date y m d strtotime 1 week 沒有問題,因為每週時間固定為7天。如果當前日期為2016 5 31,用date y m d strtotime 1 month 會產生錯誤。因為這裡把 1 month按照 30 days來算 date y m d st...

date的to char取自然周及format引數

很多時間我們需要用oracle提供的to char 函式來取得某個日期是屬於今年的第幾周.例如 to char to date 20090112 yyyymmdd ww 得到的結果是02,就是第2?可看看日曆上,2009年1月12日第三週的周一.為什麼會有這樣的問題呢?由於oracle在to cha...

date的to char取自然周及format引數

很多時間我們需要用oracle提供的to char 函式來取得某個日期是屬於今年的第幾周.例如 to char to date 20090112 yyyymmdd ww 得到的結果是02,就是第2?可看看日曆上,2009年1月12日第三週的周一.為什麼會有這樣的問題呢?由於oracle在to cha...