表结构:
方法1:
select a.* from table_test as a where 3 >
(select count(*) from table_test where brand_id = a.brand_id and addtime > a.addtime )
order by a.brand_id,a.addtime desc
方法2:
select * from
(select *,row_number() over( partition by brand_id order by addtime desc ) as a from table_test) as c
where a<4
运行sql后对应数据: