生日SQL,顯示最近14天過生日的使用者

2022-03-29 08:37:53 字數 605 閱讀 4583

select user_nickname, user_id, user_birth 

from z_userinfo 

where user_birth >= getdate() and user_birth <= dateadd(dd,15,getdate()) 

好處:1、user_birth如果有索引的話,能夠利用上索引。樓主那樣將字段放在函式中,肯定是用不上索引的。 

2.getdate()+15這種寫法不是很好,建議用sql 自帶的函式dateadd

另外一種方法:

select

user_nickname, 

user_id

, user_birth

from

z_userinfo

where

(convert

(datetime

,substring

(convert

(varchar

,user_birth),1,

6)+'

2008') 

between

getdate

() and

(getdate()+

15))

oracle 查詢最近執行過的 SQL語句

select sql text,last load time from v sql order by last load time desc select sql text,last load time from v sql where last load time is not null and ...

oracle 查詢最近執行過的 SQL語句

select sql text,last load time from v sql order by last load time desc select sql text,last load time from v sql where last load time is not null and ...

oracle 查詢最近執行過的 SQL語句

select sql text,last load time from v sql order by last load time desc select sql text,last load time from v sql where last load time is not null and ...