sql怎么写

leven1984 2011-07-18 02:27:12
id, type 两列,id为主键 ,想取同一type的前10条数据 怎么拼sql
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
agile2009 2011-07-18
  • 打赏
  • 举报
回复
select tb.* from tb where tb.id in (select top 10 tb1.id from tb tb1 where tb.type = tb1.type order by a,b )
undead4444 2011-07-18
  • 打赏
  • 举报
回复
LS+1
gogodiy 2011-07-18
  • 打赏
  • 举报
回复

;with aaa as
(select row_number() over(partition by type order by id) as row,* from table)
select * from aaa where row<=10
cd731107 2011-07-18
  • 打赏
  • 举报
回复
select *
from tb t
where id>=any (select top 10 id from tb where type = t.type order by id desc)
AcHerat 元老 2011-07-18
  • 打赏
  • 举报
回复

select *
from tb t
where id in (select top 10 id from tb where type = t.type order by id desc)

34,587

社区成员

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

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