| |

VerySource

 Forgot password?
 Register
Search
Author: 冰点飞扬

A classic sql interview question! I think I have a good time playing with sql!

[Copy link]

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-4 22:30:01
| Show all posts
declare @t table(student number int identity(1,1),
Name varchar(30), gender nvarchar(1), age int)

insert into @t
select'xw','male',18 union all
select'mc','女',18 union all
select'mc','女',18 union all
select'mc','女',18 union all
select'ww','male',21 union all
select'xw','male',18 union all
select'xw','male',18

select * from @t

delete from @t
where student number
in
(
select b. Student ID
from @t b
inner join
(
select name, gender, age
from @t
group by name, gender, age
having count(1)>1
) a
on a. name=b. name and a. gender=b. gender and a. age=b. age
)

select * from @t
--------------------
What you asked is wrong. Here it is. The NET section is much worse than the SQL section after all
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-16 17:30:01
| Show all posts
What did you write
delete A from Table A
inner jion Table B
on A. Student ID> B. Student ID and A. Name = B. Name and A. Gender = B. Gender and A. Age = B. Age
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-26 16:15:01
| Show all posts
create table students
(
sid varchar(20) primary key,
sname varchar(20),
sex varchar(2),
age int

)

insert into students
values('0001','cc','male',19)
insert into students
values('0002','a','female',11)
insert into students
values('0003','b','male',13)
insert into students
values('0004','cc','male',19)

delete from students where sid =
(
select s1.sid from students s1,students s2 where s1.sname=s2.sname and s1.sid>s2.sid
)
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 11:00:01
| Show all posts
[Quote=Quote the reply ofjsj_yyon the 11th floor:]
Basically.
[/Quote]
in change exists better
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 11:15:01
| Show all posts
The quote was wrong just now.
[Quote=quote the reply ofkcactuson the 12th floor:]
DELETE FROM Test2
where [student number] in
(select [study number]=min([study number]) from Test2 group by [name],[gender],[age] having count(*)> 1)
[/Quote]
in change exists better
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