表 A
有 product_id
和 product_name
。
表 B
有 product_id
及其相关的 values
。
如何选择 product_name
(来自表 A
)和 min
和 max
的值(来自表 B
)?
预期结果:
答案 0 :(得分:0)
你只想要join
和group by
吗?
select a.product_id, a.product_name, min(b.value), max(b.value)
from a join
b
on a.product_id = b.product_id
group by a.product_id, a.product_name;
答案 1 :(得分:0)
select product_name, MAX(value) as Maximal, MIN(value) as Minimal from a, b
where a.product_id = b.product_id
group by product_name