我有一个包含如下表的数据库:-
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
执行以下查询时:
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 的额外数据,以及日期在 01/05/2014 和 31/05/2014 之间的数据
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.
这篇关于使用 BETWEEN 作为日期调用数据时获取额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!