|
create table A (id int, name varchar (10))
insert into A (id, name)
select 1, 'DEMO'
union all
select 2, 'DEMO2'
select * from A
create table B (id int, aid int, price int)
insert into B (id, aid, price)
select 1,1,30
union all
select 2,1,32
union all
select 3,1,26
select A.id AS 'A.ID', A.name AS 'A.NAME', MAX (B.id) AS 'B.ID', B.aid as 'B.AID', MIN (B.price) AS 'B.PRICE'
from B LEFT join A on A.id = B.aid
GROUP BY A.id, A.name, B.aid |
|