| |

VerySource

 Forgot password?
 Register
Search
View: 1348|Reply: 4

How to write this SQL?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-10 12:20:01
| Show all posts |Read mode
There is a data sheet

A1 A2 mem
1001 11 Good
1001 211 Good 1
1002 SS bad
1002 DD bad
..

I want to display the first record with the same content in the A1 field
A1 A2 mem
1001 11 Good
1002 SS bad
Reply

Use magic Report

0

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-17 23:09:01
| Show all posts
select A1, first (A2), first (mem)
from table name
group by A1
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-16 18:15:01
| Show all posts
It is best to add an auto-increment field and then write the SQL statement.
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-31 13:30:02
| Show all posts
select A1, first (A2), first (mem)
from table name
group by A1



-Agree with this
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-31 14:00:02
| Show all posts
SELECT tt.A1, first(tt.A2) AS A2, first(tt.mem) AS mem
FROM tt
GROUP BY tt.A1
This is more accurate, using the same name field and solving the problem of circular reference parameters.
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