日期:2014-05-16 浏览次数:20804 次
tags page_id a 5 a 6 a 8 a 9 a 11 a 15 b 2 b 4 c 1 c 3 c 12 c 14 c 16 d 7 d 10 d 13 d 17
a 5 a 6 a 8 b 2 b 4 c 1 c 3 c 12 d 7 d 10 d 13
select tags ,page_id from ( select tags ,page_id,(select count(1) from tb_name where a.tags = tags and page_id <= a.page_id) rn from tb_name a ) t where t.rn<=3;
------解决方案--------------------
select * from table1 t where 3>(select count(*) from table1 where tags=t.tags and page_id<t.page_id)
------解决方案--------------------
在tags, page_id上建立索引
SELECT * from ttl a where 3>=(select count(*) from ttl where a.tags=tags and a.page_id>=page_id)
or
SELECT a.tags, a.page_id from ttl a left join ttl b on a.tags=b.tags and a.page_id>=b.page_id
group by a.tags, a.page_id
having count(*)<=3