| |

VerySource

 Forgot password?
 Register
Search
Author: donkey_ngacn

A SQL statement query problem (query minimum value) (urgent)

[Copy link]

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-2 21:15:01
| Show all posts
To:99429499

Pay attention to on a.id=b.aid in我是杀人狂's sql
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-2 23:15:01
| Show all posts
No one seems to write like me
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-3 11:15:01
| Show all posts
If there are two pieces of data with the same price in Table B, how to display only one
Table B
--------------
ID AID PRICE
1 1 30
2 1 32
3 1 26
4 1 26
------------------------------------------
donkey_ngacnis right
So the algorithm is improved to
select top 1 with ties A.id, A.name, B.id, B.AID, B.price
from @B B
join @A A on A.id=B.AID
order by price
I guarantee fast and accurate
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-13 17:15:01
| Show all posts
Well written, it’s OK, for me, hahaha
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-13 20:45:01
| Show all posts
I think so too. Hahaha
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-17 16:45:01
| Show all posts
select distinct * from a,b
where a.id=b.aid and
b.price = (select min(price) from b group by aid)
This is the best solution
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-21 17:45:01
| Show all posts
Are all the questions answered?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-22 00:00:01
| Show all posts
Which answer is correct, I haven’t run a correct one yet

The effect to be achieved should be to find out the lowest price of each product in Table A!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Sweden

Post time: 2020-7-23 10:15:03
| Show all posts
select a.aid as id,a.name,b.id,b.aid,b.price from a
inner join b on a.aid=b.aid
where b.price in(select min(price) from b)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-23 20:15:01
| Show all posts
Use view

create view price_view
as
select b.aid,min=min(b.price) from b group by b.aid

select a.name,a.id,price_view.aid,min from a,price_view where a.id=price_view.aid
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