有个表,里面有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)
在一个表里面,不是俩表
自连接都不知道?
自连接都不知道?
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号