mysql 查询日期时间字段的准确性
我正在使用 MySql 5.5,
我在半径会计表上使用以下查询。
查询1:
SELECT * FROM database.table WHERE framedipaddress='192.168.1.1' 和 '2011-09-09' BETWEEN acctstarttime 和 acctstoptime;
acctstarttime
和 acctstoptime
字段为 datetime
类型,格式为 YEAR-MT-DY HR:MN:SC
。
使用 query2 显示我的 query1 的结果并不总是准确的,query1 有时不会返回任何内容或返回不正确的行。
查询2:
SELECT * FROM database.table WHERE framedipaddress = '192.168.1.1' ORDER BY acctstarttime DESC LIMIT 0, 400;
是否有不同的方法来查询两个日期时间字段,或者数据库健全性/数据是问题吗?
欢迎对我的逻辑错误提出任何指导。
这是我现在查询的问题 。
I'm using MySql 5.5,
I am using the following query on a radius accounting table.
query1:
SELECT * FROM database.table WHERE framedipaddress='192.168.1.1' and '2011-09-09' BETWEEN acctstarttime AND acctstoptime;
The acctstarttime
and acctstoptime
fields are type datetime
, formatted as YEAR-MT-DY HR:MN:SC
.
Using query2 reveals my results of query1 are not always accurate, query1 sometimes will return nothing or an incorrect row.
query2:
SELECT * FROM database.table WHERE framedipaddress = '192.168.1.1' ORDER BY acctstarttime DESC LIMIT 0, 400;
Is there a different method to query two datetime
, fields, or is it the database sanity/data is the issue?
Any guidance to the errors in my logic are welcome.
Here is the question for the query I have now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
'2011-09-09' = '2011-09-09 00:00:00'
因此,您仅查询在此时间之前具有 acctstarttime 且在该时间之后具有 acctstoptime 的帐户。如果您正在查找于 2011 年 9 月 9 日开始的帐户。 那么您可以这样做
如果您正在查找于 2011 年 9 月 9 日开始和结束的帐户, 。然后执行以下操作:
仅供参考,如果您使用
BETWEEN
,它会包含边界,因此它将包含2011-09-10 00:00:00
。'2011-09-09' = '2011-09-09 00:00:00'
So you are only querying accounts that had an acctstarttime before this time AND an acctstoptime after this time.If you're looking for accounts that were started on 2011-09-09. Then you could do
If you're looking for accounts that were started and ended on 2011-09-09. Then do:
FYI if you use
BETWEEN
it includes the bounds so it would include2011-09-10 00:00:00
.