| |

VerySource

 Forgot password?
 Register
Search
View: 1806|Reply: 7

How to take the first line

[Copy link]

2

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-17 10:00:01
| Show all posts |Read mode
The existing SqlServer data table (the table name is TestTable) contains the following three columns
Number Name Other
10000 Beijing, A Dou falls with the wind
10000 Hebei sfsaadf
10000 Shanxi 23424234
10001 Eat with the wind
10001 sleep haha
10005 Don't think about it 2234234
10006 hurry up 3424234
10007 Follow the wind to spread the speed
10007 324 Follow the wind
... ... ......
How do I get the following data set
Number Name Other
10000 Beijing, A Dou falls with the wind
10001 Eat with the wind
10005 Don't think about it 2234234
10006 hurry up 3424234
10007 Follow the wind and spread the speed
... ... ...

In other words, only go to the first line of the number, no matter what else
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-12-17 12:15:01
| Show all posts
Which row should be taken, is it random?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-17 12:30:02
| Show all posts
Group first, and take the smallest
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-12-17 12:45:01
| Show all posts
select * from TestTable where 1 = (select count(1) from TestTable a where number = a. number and name<a. name) order by name
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-12-17 13:15:01
| Show all posts
select * from table
where number in
(
select min(number) from table
)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 23:15:01
| Show all posts
select *
from table name as b,
(
select number, min (name) as name
from table name
group by number
) as a
where a. number = b. number and a. name = b. name
Reply

Use magic Report

1

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-12-20 23:30:01
| Show all posts
select number, name, other
from TestTable
where number in(select number, min(name) as name
from table name
group by number)
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-12-20 23:45:01
| Show all posts
select * from tablename where other in(select top 1 other from tablename group by number order by other desc)
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