| |

VerySource

 Forgot password?
 Register
Search
View: 894|Reply: 2

sql?

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-28 21:00:01
| Show all posts |Read mode
TABLE
col1 col2 col3
 x 1 0
 x 2 1
 x 3 2
 x 3 3
 y 1 0
 y 2 1
 z 1 0
 z 1 1
 z 2 2
 z 2 3

How to return 3 records:

col1 col2 col3
 x 3 2 or x, 3,3
 y 2 1
 z 2 2 or x, 2,3
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-2 19:30:02
| Show all posts
select col1, col2, col3 = count (*) from tablename where col2 in (select max (col2) from tablename) group by col2
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-2 22:30:01
| Show all posts
select A.col1, B.col2, A.col3 from A, (select col1, max (col2) as col2 from A group by col1) B where A.col1 = B.col1 and A.col2 = b.col2
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