SQL84. 确定已售出产品项 BR01 的总数
描述
quantity | prod_id |
10 | AR01 |
100 | AR10 |
1000 | BR01 |
10001 | BR010 |
items_ordered |
1000 |
示例1
输入:
DROP TABLE IF EXISTS `OrderItems`; CREATE TABLE IF NOT EXISTS `OrderItems`( quantity INT(16) NOT NULL COMMENT '商品数量', prod_id VARCHAR(255) NOT NULL COMMENT '商品项' ); INSERT `OrderItems` VALUES (10,'AR01'),(100,'AR10'),(1000,'BR01'),(10001,'BR010');
输出:
1000.000
Mysql 解法, 执行用时: 39ms, 内存消耗: 6452KB, 提交时间: 2022-03-04
select sum(quantity) as items_ordered from OrderItems where prod_id = "BR01";
Mysql 解法, 执行用时: 39ms, 内存消耗: 6516KB, 提交时间: 2022-03-07
select sum(quantity) items_ordered from OrderItems where prod_id = 'BR01'
Mysql 解法, 执行用时: 40ms, 内存消耗: 6424KB, 提交时间: 2022-04-23
SELECT sum(quantity) FROM OrderItems WHERE prod_id = "BR01"
Mysql 解法, 执行用时: 40ms, 内存消耗: 6428KB, 提交时间: 2022-08-05
select sum(quantity) items_ordered from OrderItems where prod_id like('BR01')
Mysql 解法, 执行用时: 40ms, 内存消耗: 6436KB, 提交时间: 2022-06-03
select sum(quantity) as items_ordered from OrderItems where prod_id = 'BR01';