数据分类 前N条

liaoyukun111 2010-04-14 04:51:59
大概有一个这样的表
cid names,types
第三个字段是分类  
求第一分类的前N条数据  cid不一定连续
...全文
83 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luo7269315 2010-04-15
  • 打赏
  • 举报
回复
不懂。。。学习学习。。。
水族杰纶 2010-04-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wufeng4552 的回复:]
SQL code
select *
from tb t
where (select count(*)from tb where types=t.types and cid>t.cid)<3
[/Quote]
select * 
from tb t
where (select count(*)from tb where types=t.types and cid>t.cid)<3
水族杰纶 2010-04-14
  • 打赏
  • 举报
回复
select * 
from tb t
whre (select count(*)from tb where types=t.types and cid>t.cid)<3
chuifengde 2010-04-14
  • 打赏
  • 举报
回复
SELECT * FROM @a a WHERE cid in(SELECT TOP 3 htrq FROM @a WHERE types=a.types ORDER BY cid)
htl258_Tony 2010-04-14
  • 打赏
  • 举报
回复
--2005

select * from (select rn=row_number()over(partition by types order by cid),* from tb) t where rn<=n
htl258_Tony 2010-04-14
  • 打赏
  • 举报
回复

select * from tb t where cid in(select top n cid from tb where types=t.types order by cid)
liaoyukun111 2010-04-14
  • 打赏
  • 举报
回复
是每一个的分类的前N条

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧