有个表,里面有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最高效。
$time = time() - 600;
select xx_id,count(xx_id) count from tablename where type = 1 and time > $time group by xx_id;