求 mysql 一条查询语句

shenmdouyourenjiaole 2011-11-11 01:12:52
数据库结构很简单,有: id ,ip ,date 三个字段。

我想查询 在距离现在10 分钟内, 同一个ip的入库记录数,关键问题是 那个 10 分钟我不会控制,不太了解 mysql中的时间函数是怎么用的,有 date_sub 以及 date_add sysdate 但是 我写的语句却不正确,请指点!
我的sql语句是:

select count(*) from ask_account_tell where account_ip = '119.253.59.50' and account_date > date_sub(sysdate(),interval 10 minute) and account_date < sysdate()

...全文
985 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 acmain_chm 的回复:]

贴一条你认为符合条件的记录出来以供分析。 另外贴一下你的 desc ask_account_tell
[/Quote]



谢谢你哈 我已经解决了,sql语句如下,我把 account_date 改成日期格式了,不是时间戳形式了。
select count(*) as nums from ask_account_tell where account_ip = '."'$ip'".' and account_date > DATE_SUB(now(),INTERVAL 10 MINUTE) and account_date < now()'
  • 打赏
  • 举报
回复
并且我accoount_date 存储的是 时间戳的格式。
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 acmain_chm 的回复:]

贴一条你认为符合条件的记录出来以供分析。 另外贴一下你的 desc ask_account_tell
[/Quote]


也可以这样说 就是 数据库中,SELECT count( * )FROM ask_account_tell WHERE account_date > now( ) - INTERVAL 20 MINUTE 单运行这个sql,查询不出来结果桌面/jj.png
ACMAIN_CHM 2011-11-11
  • 打赏
  • 举报
回复
贴一条你认为符合条件的记录出来以供分析。 另外贴一下你的 desc ask_account_tell
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acmain_chm 的回复:]

SQL code
select count(*) from ask_account_tell
where account_ip = '119.253.59.50'
and account_date > now()+interval 10 minute and account_date<now()
[/Quote]



不怎么好使啊 我直接先运行
select count(*) from ask_account_tell
where account_date > now() - interval 24 hour

结果集也是 0 按说是应该有记录的,不应该是 0 的
ACMAIN_CHM 2011-11-11
  • 打赏
  • 举报
回复
select count(*) from ask_account_tell 
where account_ip = '119.253.59.50'
and account_date > now()+interval 10 minute and account_date<now()

56,682

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧