| |

VerySource

 Forgot password?
 Register
Search
Author: donkey_ngacn

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

[Copy link]

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-25 20:15:01
| Show all posts
select a.id,A.NAME, B.ID,B.AID,B.PRICE from a,b,(select aid, min(price) as minprice from b group by aid) as c where a.id = b. aid and a.id = c.aid and b.price = c.minprice;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-27 17:00:01
| Show all posts
If you don't need to check the corresponding b.id, you can do this
select a.name,min(b.price)
from a,b
where a.id=b.aid
group by a.name
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-29 19:30:01
| Show all posts
select a.aid,a.name,b.bid,b.aid,b.price
from a,b
where a.aid=b.aid and b.price=(select min(b.price) from b);
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-30 22:00:01
| Show all posts
create table tblA(ID int, name varchar(15))
create table tblB(ID int, AID int, price float)

insert into tblA values(1,'Demo')
insert into tblA values(2,'Demo2')

insert into tblB values(1,1,30)
insert into tblB values(2,1,32)
insert into tblB values(3,1,26)


select tblA.id, tblA.name, tblB.id, tblB.aid, tblB.price
from tblA,tblB
where tblA.id=tblB.aid
and tblB.price = (select min(tblB.price) from tblB)
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Russia

Post time: 2020-7-30 23:15:01
| Show all posts
select distinct *
from a,b
where a.id = (select max(id) from a) and b.id = (select max(id) from b)

-------------------------------------------------- -------------------------------

tocv4bf5d65fd:

Your method is wrong, don't mislead others!
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-31 00:45:01
| Show all posts
select *
from a inner join b t1 on a.id = t1.id
where not exists (select 1 from b where aid = t1.aid and price <t1.price)

-------------------------------------------------- ----------------------------------
tomichealhenry:

Your method is not feasible either!
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