SELECT a.*from inventory_seller_product a innerJOIN(select product, seller,max(total_sold)as total_sold from inventory_seller_product groupby product)b
on a.product=b.product and a.total_sold=b.total_sold AND a.product IN('1','2')orderby a.product;
二、隐式内连接
SELECT a.*from inventory_seller_product as a
where total_sold =(selectmax(total_sold)from inventory_seller_product as b where a.product = b.product )and product in('1','2');
去重(最值相等时)
SELECT*FROM(SELECT a.*from inventory_seller_product as a
where total_sold =(selectmax(total_sold)from inventory_seller_product as b where a.product = b.product )and product in('1','2')) c
groupby product, total_sold
一、显式内连接SELECT a.* from inventory_seller_product a inner JOIN(select product, seller,max(total_sold) as total_sold from inventory_seller_product group by product)bon a.product=b.product and a.total_sold=b.total_sold AND a.product IN (‘1’, ‘2’)order by a