1
feiyuanqiu 2014-09-04 20:11:00 +08:00 1
表应该还有个主键吧...试了一下,用了子查询,性能有问题...坐等其他大大的方法
SELECT a.* FROM test_2 a JOIN (SELECT area_id, product_id, MIN(price) AS price FROM test_2 GROUP BY area_id, product_id) b ON a.`area_id` = b.area_id AND a.`product_id` = b.product_id AND a.`price` = b.price |
2
refresh OP @feiyuanqiu 不一定会有主键,实际上这几个字段并不是同一个表中出来的,但主键对这个查询应该没有影响吧。
|
3
fengchang 2014-09-05 10:03:36 +08:00
如果要查出该价格对应的seller_id,子查询应该是难免的,除了1楼提供的方法,还可以
SELECT * FROM product WHERE (product_id,area_id,price) IN ( SELECT product_id, area_id, MIN(price) price FROM product GROUP BY product_id, area_id ); 但是性能不如1楼 |