mysql分组后,取每组的前3条数据并且有顺序

不列出表结构及测试数据,只能这样大概写个思路了:select a.from (select t1.*,(select count(*)+1 from 表 where 分组字段=t1.分组字段 and 排序字段
mysql分组后,取每组的前3条数据并且有顺序
不列出表结构及测试数据,只能这样大概写个思路了:

select a.*
from
(
select t1.*,(select count(*)+1 from 表 where 分组字段=t1.分组字段 and 排序字段<t1.排序字段) as group_id
from 表 t1
) a
where a.group_id<=32010-08-06
select *
from tb k
where 3>(select count(*) from tb where k.分组字段=分组字段 and 你的排序字段>k.你的排序字段)2010-08-06
mengvlog 阅读 52 次 更新于 2025-12-18 05:49:26 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部