sql select查询工作异常 [英] Sql select query working abnormally
问题描述
我对sql中datetime数据的逻辑运算符的性质感到困惑。
在我的数据库表中RecordDateTime保存如下:
2014-04-09 15:28:32.000
我正在检索此查询:
I am confused by the nature of logical operators upon datetime data in sql.
In my database's table RecordDateTime is saved like:
2014-04-09 15:28:32.000
I am retrieving on basis of this query:
select * FROM [GPSDB].[dbo].[Coordinates] where IMEI= '354400055967495' and RecordedDateTime >= '2014-04-09 15:28:32.000' and RecordedDateTime <= '2014-04-09 15:39:20.000'
现在返回4行,介于这些行之间两个日期的范围或等于预期,但混淆从这里开始从第一个日期移动秒部分然后它仍然有效并返回相同的结果集即
Now it returns 4 rows which falls between these both dates range or equal as expected but confusion starts from here when i remove Seconds part from first date then still it works and returns same result set i.e.
select * FROM [GPSDB].[dbo].[Coordinates] where IMEI= '354400055967495'and RecordedDateTime >= '2014-04-09 15:28' and RecordedDateTime <= '2014-04-09 15:39:20.000;
但如果我从第二个日期删除秒部分,那么它只返回一行,并提供第一个日期的匹配时间。奇怪的 ? :/
请帮助。
but if i remove seconds part from 2nd date then it returns only one row with matching time of first date being provided. Weird ? :/
Help Please.
推荐答案
这是第二次约会'2014-04-09 15: 39:20.000'
如果你写'2014-04-09 15:39'那么它默认需要几秒00.000 ...
this is second date '2014-04-09 15:39:20.000'
if you write '2014-04-09 15:39' then it will be take seconds 00.000 by default so...
'2014-04-09 15:39' = '2014-04-09 15:39:00.000'
所以, RecordedDateTime大于'2014-04-09 15:39: 00.000 '的记录将不会显示
因为'2014-04-09 15:39: 20.000 '不小于或等于'2014-04-09 15:39: 00.000 '
快乐编码!
:)
so, the records having RecordedDateTime greater than '2014-04-09 15:39:00.000' will not be displayed
because '2014-04-09 15:39:20.000' is not less than or equal to '2014-04-09 15:39:00.000'
Happy Coding!
:)
这篇关于sql select查询工作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!