MySQL查询日期,两个日期字段之间 [英] mysql query of a date, between two date fields

查看:885
本文介绍了MySQL查询日期,两个日期字段之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySql 5.5.

I'm using MySql 5.5.

我需要找到一个具有特定IP地址的日期的用户ID.

I need to find a userid on a date with a particular ip address.

这些字段是用户ID,ip地址,开始日期,结束日期.

The fields are userid, ipaddress, startdate, enddate.

例如,我正在寻找2011年9月12日IP地址为192.168.1.1的用户ID.

So for instance I am looking for a userid with ip address 192.168.1.1 on Sep 12 2011.

查询将类似 select * 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.

推荐答案

不清楚是否要:

'2011-12-09' BETWEEN startdate AND enddate

或:

'2011-12-09' = startdate AND '2011-12-09' = enddate

这篇关于MySQL查询日期,两个日期字段之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆