SQL72. 检索并列出已订购产品的清单
描述
prod_id | order_num | quantity |
BR01 | a1 | 105 |
BR02 | a2 | 1100 |
BR02 | a2 | 200 |
BR03 | a4 | 1121 |
BR017 | a5 | 10 |
BR02 | a2 | 19 |
BR017 | a7 | 5 |
order_num | prod_id | quantity |
a1 | BR01 | 105 |
a2 | BR02 | 1100 |
a2 | BR02 | 200 |
a4 | BR03 | 1121 |
示例1
输入:
DROP TABLE IF EXISTS `OrderItems`; CREATE TABLE IF NOT EXISTS `OrderItems`( prod_id VARCHAR(255) NOT NULL COMMENT '商品号', order_num VARCHAR(255) NOT NULL COMMENT '商品订单号', quantity INT(255) NOT NULL COMMENT '商品数量' ); INSERT `OrderItems` VALUES ('BR01','a1','105'),('BR02','a2','1100'),('BR02','a2','200'),('BR03','a4','1121'),('BR017','a5','10'),('BR02','a2','19'),('BR017','a7','5')
输出:
a1|BR01|105 a2|BR02|1100 a2|BR02|200 a4|BR03|1121
Mysql 解法, 执行用时: 38ms, 内存消耗: 6448KB, 提交时间: 2022-03-07
select order_num,prod_id,quantity from OrderItems where quantity >100 and prod_id in('BR01', 'BR02', 'BR03')
Mysql 解法, 执行用时: 38ms, 内存消耗: 6524KB, 提交时间: 2022-03-07
select order_num,prod_id,quantity from OrderItems where quantity>=100
Mysql 解法, 执行用时: 39ms, 内存消耗: 6440KB, 提交时间: 2022-03-04
SELECT order_num,prod_id,quantity FROM OrderItems WHERE prod_id IN ('BR01','BR02','BR03') AND quantity>=100;
Mysql 解法, 执行用时: 39ms, 内存消耗: 6444KB, 提交时间: 2022-03-04
SELECT order_num, prod_id, quantity FROM OrderItems WHERE prod_id IN ('BR01', 'BR02', 'BR03') AND quantity >= 100
Mysql 解法, 执行用时: 39ms, 内存消耗: 6456KB, 提交时间: 2022-03-05
select order_num,prod_id,quantity from OrderItems where quantity>=100 and (prod_id = 'BR01' or prod_id='BR02' or prod_id='BR03')