| |

VerySource

 Forgot password?
 Register
Search
Author: kentotoro

There are 10 records in a table. How to extract the 5th to 8th data without using the id number?

[Copy link]

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-8 20:30:01
| Show all posts
It is estimated that the landlord means not to do according to the order.
How about:
--Build an example table:
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'

--check sentence
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
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list