LeetCode 1173.即时食物配送

数据准备

sql 复制代码
drop table Delivery;

Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date);
Truncate table Delivery;
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '5', '2019-08-02', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-11');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-26');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '4', '2019-08-21', '2019-08-22');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13');

需求

写一条 SQL查询语句获取即时订单所占的百分比,保留两位小数。

输入

输出

sql 复制代码
select round(count(if(order_date=customer_pref_delivery_date,1,null))/count(1)*100,2) as immediate_percentage
from Delivery;
相关推荐
dinglu1030DL2 分钟前
CSS如何实现背景颜色的棋盘格分布_利用repeating-gradient
jvm·数据库·python
2303_821287385 分钟前
Golang reflect反射怎么用_Golang反射教程【通俗】
jvm·数据库·python
Mike117.23 分钟前
GBase 8c 里 search_path 没管住,SQL 可能跑到另一个对象上
数据库·sql·postgresql
VALENIAN瓦伦尼安教学设备29 分钟前
填补国内空白!瓦伦尼安发布首台船机机械故障诊断振动实验台
大数据·人工智能·嵌入式硬件
升鲜宝供应链及收银系统源代码服务32 分钟前
升鲜宝云商品库功能设计与数据库表结构详细文档(一)---升鲜宝生鲜配送供应链管理系统源代码服务
数据库·生鲜配送源代码·供应链源代码·生鲜供应链源代码·升鲜宝供应链管理系统源代码·b2b客户订货源代码
2301_7838486537 分钟前
如何用 IDBKeyRange 范围匹配检索特定区间的本地数据
jvm·数据库·python
解决问题no解决代码问题38 分钟前
【无标题】
数据库
倒流时光三十年39 分钟前
PostgreSQL 中的 NULL 陷阱:从一次排除过滤说起
java·数据库·postgresql
2601_9515159539 分钟前
护眼照明进入深度洗牌期:书客SUN2如何重塑健康光行业规则?
大数据·人工智能·书客护眼大路灯·爱眼护眼·护眼大路灯
weixin_444012931 小时前
SQL处理大规模分组聚合的内存限制_调整服务器配置.txt
jvm·数据库·python