列表

详情


SQL68. 返回更高价格的产品

描述

Products 表
prod_id prod_name
prod_price
a0018 sockets 9.49
a0019 iphone13 600
b0019
gucci t-shirts 1000

【问题】编写 SQL 语句,从 Products 表中检索产品 ID(prod_id)和产品名称(prod_name),只返回价格为 9 美元或更高的产品。
【示例答案】返回prod_id商品id和prod_name商品名称
prod_id prod_name
a0018 sockets
a0019 iphone13
b0019
gucci t-shirts

示例1

输入:

DROP TABLE IF EXISTS `Products`;
CREATE TABLE IF NOT EXISTS `Products` (
`prod_id` VARCHAR(255) NOT NULL COMMENT '产品 ID',
`prod_name` VARCHAR(255) NOT NULL COMMENT '产品名称',
`prod_price` DOUBLE NOT NULL COMMENT '产品价格'
);
INSERT INTO `Products` VALUES ('a0011','usb',9.49),
('a0019','iphone13',600),
('b0019','gucci t-shirts',1000);

输出:

a0011|usb
a0019|iphone13
b0019|gucci t-shirts

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Mysql 解法, 执行用时: 38ms, 内存消耗: 6500KB, 提交时间: 2022-03-07

select prod_id,prod_name
from Products
where prod_price>=9

Mysql 解法, 执行用时: 38ms, 内存消耗: 6500KB, 提交时间: 2022-03-02

select 
prod_id,prod_name
from Products where 
prod_price>=9

Mysql 解法, 执行用时: 39ms, 内存消耗: 6408KB, 提交时间: 2022-03-03

select prod_id,prod_name
from Products 

Mysql 解法, 执行用时: 39ms, 内存消耗: 6412KB, 提交时间: 2022-03-02

select prod_id,prod_name  from Products
where prod_price>=9

Mysql 解法, 执行用时: 39ms, 内存消耗: 6424KB, 提交时间: 2022-03-06

select prod_id,prod_name from Products
where prod_price >= 9