这个SQL语句怎么写?

ItOldHorse 2003-12-23 05:44:25
这个SQL语句怎么写?

bianhao leixing
1 大柜
2 大柜
3 小柜
4 大柜
5 大柜
7 小柜
11 大柜
12 大柜
13 小柜
15 大柜
25 大柜
27 小柜

问题一:怎么写SQL语句:显示条件为 leixing='大柜' and 第M(M=3)个记录开始的N(N=2)条记录
显示结果为如下:
bianhao leixing
5 大柜
11 大柜

问题二:如果要显示条件为 leixing='大柜' and 第9个记录开始的2条记录 应该是没有显示的记录对不对?

因为leixing='大柜'的记录一共只有8个




...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dlpseeyou 2003-12-23
  • 打赏
  • 举报
回复
select top 2 * from table where leixing = '大柜' and id not (select top 3 * from table where leixing = '大柜')
shuiniu 2003-12-23
  • 打赏
  • 举报
回复
select identity(int)id ,* into #temp from yourtable
--1.
select top 2 * from #temp where leixing = '大柜' and id >= 3 and (id - 3) % 2 = 0
--2
select top 2 * from #temp where leixing = '大柜' and id >= 9 and (id - 9) % 2 = 0

drop table #temp
wzh1215 2003-12-23
  • 打赏
  • 举报
回复
理解错了,再来,不知这次对不对?
1.
select identity(int,1,1) id,* into #aa from tablename where leixing='大柜'
select top 2 * from #aa where id>=3
2.对,试一试
select top 2 * from #aa where id>=9
愉快的登山者 2003-12-23
  • 打赏
  • 举报
回复
问题一:
select top 2 * from tablename
where bianhao not in (select top 3 from bianhao from tablename where leixing='大柜' order by bianhao)
and leixing='大柜'
order by bianhao
wzh1215 2003-12-23
  • 打赏
  • 举报
回复
1.
select identity(int,1,1) id,* into #aa from tablename
select top 2 * from #aa where leixing='大柜' and id>=3
2.不对,试一下就知道了!
select top 2 * from #aa where leixing='大柜' and id>=9

34,873

社区成员

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

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