利用变量实现
set @c_id:=null, @rownum:=0;
select
*
from
(SELECT t.*,
@rownum:= (case when @c_id = t.c_id then @rownum + 1 else 1 end) count,
@c_id:=t.c_id
FROM t_class_message t
order by t.c_id asc, t.create_time desc ) T
where count < 4 ;
利用变量实现
set @c_id:=null, @rownum:=0;
select
*
from
(SELECT t.*,
@rownum:= (case when @c_id = t.c_id then @rownum + 1 else 1 end) count,
@c_id:=t.c_id
FROM t_class_message t
order by t.c_id asc, t.create_time desc ) T
where count < 4 ;
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。