sql查询问题

zhaoyong2006 2015-07-13 05:10:13
有个表,里面有xx_id、time和type两个字段,大体是这样

xx_id time type
1 2015-07-08 12:00:00 0
1 2015-07-08 12:05:01 1
2 2015-07-08 12:25:11 0
2 2015-07-08 12:35:21 1
我想查到xx_id相同并对应type为0,1 time时间相差10分钟内的个数,怎么组织sql最高效。
...全文
136 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoyong2006 2015-07-14
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
自连接都不知道?
奥,解决了,thx
xuzuning 2015-07-13
  • 打赏
  • 举报
回复
自连接都不知道?
zhaoyong2006 2015-07-13
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
select * from 表 a, 表 b where a.xx_id=b.xx_id and a.type=0 and b.type=1 and b.time>a.time and adddate(a.time, INTERVAL 10 MINUTE)<=b.time
在一个表里面,不是俩表
xuzuning 2015-07-13
  • 打赏
  • 举报
回复
select * from 表 a, 表 b where a.xx_id=b.xx_id and a.type=0 and b.type=1 and b.time>a.time and adddate(a.time, INTERVAL 10 MINUTE)<=b.time

21,895

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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