Oracle查詢本週 本月 本年的記錄

2021-07-05 08:44:03 字數 667 閱讀 1052

trunc(date,[fmt])

其中:date 為必要引數,是輸入的乙個日期值

fmt 引數可忽略,是日期格式,用以指定的元素格式來截去輸入的日期值。忽略它則由最近的日期截去

下面是該函式的使用情況:

trunc(sysdate,'yyyy') --返回當年第一天.

trunc(sysdate,'mm') --返回當月第一天.

trunc(sysdate,'d') --返回當前星期的第一天.

查詢本週的記錄:

select * from test t where t.time >=trunc(sysdate,'d') and t.time<=trunc(sysdate,'d')+6;
查詢本月的記錄:

select * from test t where t.time >=trunc(sysdate, 'mm') and t.time<=last_day(sysdate);

查詢本年的記錄:

select * from test t where t.time >=trunc(sysdate,'yyyy') and t.time<=add_months(trunc(sysdate,'yyyy'),12)-1

sql查詢本週本月本年

1.乙個月第一天的 select dateadd mm,datediff mm,0,getdate 0 2.本周一 select dateadd wk,datediff wk,0,getdate 0 select dateadd wk,datediff wk,0,getdate 6 3.一年的第一天...

mysql查詢,本月 本週 本年

mysql查詢,本月 本週 本年 今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 本週 select from 表名 where yearwee...

mysql查詢本年本月本週的資料

mysql查詢本年本月的資料 查詢本年本月的資料的語句如下 平時還是需要積累一下sql的寫法,一條好的sql能減少很多 量。查詢本年度,本年度各個月的資料,需要使用mysql的一些方法。select time count as sums,dbname,month time createtime fr...