【SQL必知必会】SQL6 按照数量和价格排序

1.题目链接

SQL6 按照数量和价格排序

2.题目描述

描述
假设有一个OrderItems表
quantity	item_price
1	         100
10	         1003
2            500

【问题】
编写 SQL 语句,显示 OrderItems 表中的数量(quantity)和价格(item_price),并按数量由多到少、价格由高到低排序。

【示例答案】
返回quantity和item_price
示例1
输入:
DROP TABLE IF EXISTS `OrderItems`;
CREATE TABLE IF NOT EXISTS `OrderItems` (
  `quantity` INT(64) NOT NULL COMMENT '数量',
  `item_price` INT(64) NOT NULL COMMENT '订单价格'
);
INSERT INTO `OrderItems` VALUES (1,100),
(10,1003),
(2,500);
复制
输出:
10|1003
2|500
1|100

3.题解

select ois.quantity, ois.item_price from OrderItems ois order by ois.quantity desc, ois.item_price desc;

优化

select
  ois.quantity,
  ois.item_price
from
  OrderItems ois
order by
  ois.quantity desc,
  ois.item_price desc;
全部评论

相关推荐

02-28 01:18
已编辑
南昌大学 后端工程师
黑皮白袜臭脚体育生:把开源经历放个人项目上边应该更好,就像大部分人都把实习经历放个人项目上边
点赞 评论 收藏
分享
SHC2:春招先狠狠投递,然后你看看能不能申请香港新加坡的一年制master,花不了多少钱,或者现在赶紧去刷一段实习。HR专业考研没必要
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务