mysql 查询两个日期字段之间的日期
我正在使用 MySql 5.5。
我需要找到具有特定 IP 地址的日期的用户 ID。
这些字段是用户 ID、IP 地址、开始日期、结束日期。
例如,我正在寻找 2011 年 9 月 12 日 IP 地址为 192.168.1.1 的用户 ID。
查询将类似 select * from database where ipaddress='192.168.1.1' and 2011-12-09 is in(startdate and enddate);
欢迎指出此逻辑缺陷的任何帮助。谢谢。
I'm using MySql 5.5.
I need to find a userid on a date with a particular ip address.
The fields are userid, ipaddress, startdate, enddate.
So for instance I am looking for a userid with ip address 192.168.1.1 on Sep 12 2011.
the query would be similarselect * from database where ipaddress='192.168.1.1' and 2011-12-09 is in(startdate and enddate);
Any help to pointing out this logic flaw is welcome. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不太清楚您是否想要:
或:
It's not very clear if you want:
or:
明显的解决方案是这样的:
但是有一个快捷方式 使用 < code>BETWEEN 所以你可以简单地写:
注意:
BETWEEN
也适用于数字、字符串和其他东西,并且可以否定它通过写作NOT BETWEEN
- 有时非常有用。the obvious solution would be like:
but theres a shortcut using
BETWEEN
so you can simply write:note:
BETWEEN
also works for numbers, strings and other stuff, and it's possible to negate it by writingNOT BETWEEN
- quite useful sometimes.由于有开始和结束日期,可能是这样的:
或者正如 ypercube 所指出的,您可以使用
BETWEEN
:Since there is a start and end date, maybe something along the line of:
Or as pointed out by ypercube you can use
BETWEEN
: