| |

VerySource

 Forgot password?
 Register
Search
View: 882|Reply: 3

Urgently ask for a SQL sentence!

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-12-10 09:00:01
| Show all posts |Read mode
For example table aa:
aa bb cc
1 255 20161212
1 15 20161210
2 33 20160612
2 11 20160101
Sorted by DESC by cc,
For example, I want to delete the latest time data in where aa='2'or other places.
Result table aa:
aa bb cc
1 255 20161212
2 33 20160612

Thank you!
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-10 13:15:01
| Show all posts
delect from aa where aa='2'
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-10 13:30:01
| Show all posts
create table tt
(
  aa int,
  bb int,
  cc varchar(08)
)
insert into tt
select 1, 255, '20161212' union
select 1, 15, '20161210' union
select 2, 33, '20160612' union
select 2, 11, '20160101'

select a.*
from tt a
where not exists
(select 1 from tt where aa = a.aa and cc> a.cc)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-10 18:45:01
| Show all posts
delete from t where aa=2 and cc in (select max (cc) from t where aa =2)
select * from t
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