SQL107. 将两个 SELECT 语句结合起来(二)
描述
prod_id | quantity |
a0001 | 105 |
a0002 | 100 |
a0002 | 200 |
a0013 | 1121 |
a0003 | 10 |
a0003 | 19 |
a0003 | 5 |
BNBG | 10002 |
prod_id | quantity |
a0002 | 100 |
BNBG | 10002 |
示例1
输入:
DROP TABLE IF EXISTS `OrderItems`; CREATE TABLE IF NOT EXISTS `OrderItems`( prod_id VARCHAR(255) NOT NULL COMMENT '产品id', quantity VARCHAR(255) NOT NULL COMMENT '商品数量' ); INSERT `OrderItems` VALUES ('a0001',105),('a0002',100),('a0002',200),('a0013',1121),('a0003',10),('a0003',19),('a0003',5),('BNBG',10002);
输出:
a0002|100.000 BNBG|10002.000
Mysql 解法, 执行用时: 38ms, 内存消耗: 6432KB, 提交时间: 2022-03-03
select prod_id, quantity from OrderItems where quantity=100 or prod_id like 'BNBG%' order by prod_id
Mysql 解法, 执行用时: 39ms, 内存消耗: 6452KB, 提交时间: 2022-03-07
select prod_id,quantity from OrderItems where quantity=100 or prod_id like 'BNBG%' order by prod_id
Mysql 解法, 执行用时: 39ms, 内存消耗: 6508KB, 提交时间: 2022-03-05
select prod_id,quantity from OrderItems where quantity=100 or prod_id like 'BNBG%' order by prod_id;
Mysql 解法, 执行用时: 39ms, 内存消耗: 6552KB, 提交时间: 2022-03-07
select prod_id ,quantity from OrderItems where quantity = 100 or prod_id like 'BNBG%'
Mysql 解法, 执行用时: 39ms, 内存消耗: 6568KB, 提交时间: 2022-03-06
SELECT prod_id,quantity FROM OrderItems WHERE quantity=100 OR prod_id LIKE'BNBG%'