Home > Backend Development > PHP Tutorial > sql查询问题

sql查询问题

WBOY
Release: 2016-06-23 13:30:45
Original
916 people have browsed it

有个表,里面有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最高效。


回复讨论(解决方案)

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)

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)

在一个表里面,不是俩表

自连接都不知道?

自连接都不知道?



奥,解决了,thx
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template