問題描述
我有一個(gè)包含如下表的數(shù)據(jù)庫(kù):-
I have a database with a table like:-
ID Name Amount Date
001 abc 200 01/05/2014
001 abc 200 02/05/2014
001 abc 200 03/05/2014
.
.
.
001 abc 200 31/05/2014
001 abc 200 01/06/2014
001 abc 200 02/06/2014
執(zhí)行以下查詢時(shí):
SELECT *
FROM table_name
WHERE Date_ between '01/05/2014' AND '31/05/2014'
ORDER BY CONVERT(DateTime, Date_, 103) DESC";
它顯示了考慮日期 01/06/2014 和 02/06/2014 的額外數(shù)據(jù),以及日期在 01/05/2014 和 31/05/2014 之間的數(shù)據(jù)
it is showing an extra data considering the dates 01/06/2014 and 02/06/2014, along with data of date between 01/05/2014 and 31/05/2014
如何解決?
推薦答案
你的中間不行,你需要使用-
your between will not work, you will need to use -
條件為
CONVERT(DateTime, Date_, 103) >= CONVERT(DateTime, '01/05/2014', 103) 和 CONVERT(DateTime, Date_, 103) <= CONVERT(DateTime, '31/05/2014', 103)
在您的 where 條件下.范圍條件不能用于過濾日期之間的記錄.
in your where condition. Range condition will not serve your purpose of filtering the records between dates.
這篇關(guān)于使用 BETWEEN 作為日期調(diào)用數(shù)據(jù)時(shí)獲取額外數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!