sql server 按時間段查詢

2022-05-01 07:36:06 字數 863 閱讀 1052

在寫按時間段查詢的sql語句的時候 一般我們會這麼寫查詢條件:

where date>='2010-01-01' and date<='2010-10-1'。

但是在實執行sql時些語句會轉換成這樣:

where date>='2010-01-01 0:00:00' and date<='2010-10-1:0:00:00',再看這個條件的話,也許就會有些明白,

那就是'2010-10-1 0:00:00' 之後的資料例如('2010-10-1:08:25:00')查不到,也就是說2010-10-1的資料查不到。

知道原因了可以修改查詢條件為:

where date>='2010-01-01' and date<='2010-10-1 23:59:59' 或 where date>='2010-01-01' and date<='2010-10-2'。

在寫按時間段查詢的sql語句的時候 一般我們會這麼寫查詢條件:

where date>='2010-01-01' and date<='2010-10-1'。

但是在實執行sql時些語句會轉換成這樣:

where date>='2010-01-01 0:00:00' and date<='2010-10-1:0:00:00',再看這個條件的話,也許就會有些明白,

那就是'2010-10-1 0:00:00' 之後的資料例如('2010-10-1:08:25:00')查不到,也就是說2010-10-1的資料查不到。

知道原因了可以修改查詢條件為:

where date>='2010-01-01' and date<='2010-10-1 23:59:59' 或 where date>='2010-01-01' and date<='2010-10-2'。

Spring Jpa 按時間段查詢

專案中有需求要按照名稱模糊查詢和時間段查詢資料,可能只有名稱沒有時間,也可能只有時間沒有名稱,也可能這幾個引數同時匹配,所以要多條件動態查詢。jpaspecificationexecutor 介面提供很多條件查詢方法 public inte ce jpaspecificationexecutor 比...

MS Access 按時間段查詢資料

access 總是有各種各樣的坑。比如資料查詢需要按時間段進行查詢,需要精確到秒 查詢一 不能用 select from yourtable where yourtimefield 2014 04 04 14 24 03 and yourtimefield 2014 04 04 14 24 05 看...

MySql 按時間段查詢資料方法

格式為2008 06 16 查詢出當天資料 select from table where date 時間字段 curdate 查詢出當月字段 select from table where month 時間字段 month now 時間格式為1219876 unix時間,只要應用 from uni...