1. 程式人生 > >mysql where if 查詢

mysql where if 查詢

篩選request_time  離現在是10天或者15天之內的資料,request_time 欄位預設為空  ,如果直接用where條件語句,request_time為空的資料就會漏掉,當request_time 不為空的時候在判斷天數,這樣為空的資料可一起查詢出來, 

格式:IF(<condition>,<value if true>,<value if false>)  

例子:   where  if (request_time is not null,request_time<=1525536000,1=1);