SQL87. 每个供应商成本最低的产品
描述
vend_id | prod_price |
a0011 | 100 |
a0019 | 0.1 |
b0019 | 1000 |
b0019 | 6980 |
b0019 | 20 |
vend_id | cheapest_item |
a0019 | 0.1 |
b0019 | 20 |
a0011 | 100 |
示例1
输入:
DROP TABLE IF EXISTS `Products`; CREATE TABLE IF NOT EXISTS `Products` ( `vend_id` VARCHAR(255) NOT NULL COMMENT '供应商ID', `prod_price` DOUBLE NOT NULL COMMENT '产品价格' ); INSERT INTO `Products` VALUES ('a0011',100), ('a0019',0.1), ('b0019',1000), ('b0019',6980), ('b0019',20);
输出:
vend_id|cheapest_item a0019|0.100 b0019|20.000 a0011|100.000
Mysql 解法, 执行用时: 38ms, 内存消耗: 6600KB, 提交时间: 2022-03-02
SELECT vend_id,MIN(prod_price) as cheapest_item FROM Products GROUP BY vend_id ORDER BY cheapest_item
Mysql 解法, 执行用时: 38ms, 内存消耗: 6652KB, 提交时间: 2022-03-04
select vend_id,min(prod_price) as cheapest_item from Products group by vend_id order by cheapest_item asc
Mysql 解法, 执行用时: 39ms, 内存消耗: 6496KB, 提交时间: 2022-03-05
select vend_id,min(prod_price) as cheapest_item from Products group by vend_id order by cheapest_item
Mysql 解法, 执行用时: 39ms, 内存消耗: 6500KB, 提交时间: 2022-03-06
select vend_id, min(prod_price) cheapest_item from Products group by vend_id order by cheapest_item
Mysql 解法, 执行用时: 39ms, 内存消耗: 6504KB, 提交时间: 2022-03-08
select vend_id,min(prod_price) as cheapest_item from Products group by vend_id order by cheapest_item ;