VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
12
返回列表 发新帖
楼主: kentotoro

一个表中有10条记录,在不使用id号的情况下,如何提取出第5到第8条的数据?

[复制链接]

0

主题

6

帖子

6.00

积分

新手上路

Rank: 1

积分
6.00
发表于 2020-6-8 20:30:01 | 显示全部楼层
估计楼主的意思是不要根据排序来做。
这样如何:
--建示例表:
create table #ddd
([id] int,[name] varchar(20),remark varchar(200)
)
insert into  #ddd
select 1,'a','dsfadsf'
union
select 2,'b','dryh'
union
select 3,'c','uui'
union
select 4,'d','gjk'
union
select 5,'e','dsfradsf'
union
select 6,'f','dsfadsf'
union
select 7,'g','fdf'
union
select 8,'h','dfdf'
union
select 9,'i','jki'
union
select 10,'j','reta'

--查询语句
select * from
(
select top 8 a.* from (select * from #ddd) a
union all
select top 4 b.* from (select * from #ddd) b
) c
group by [id],[name],remark
having count(*)=1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表