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;
相关推荐
IT枫斗者枫哥4 小时前
MyBatis一对多分页:LIMIT 20,为什么凑不齐20个订单?
java·数据库
明月_清风4 小时前
数据进入平台后怎么处理?一文搞懂 ETL
大数据·后端·数据分析
Flynt4 小时前
"MySQL搜不动就上ES"?我先在50万行数据上测了它自带的ngram全文索引
mysql·elasticsearch·搜索引擎
明月_清风4 小时前
数据处理完放在哪里?一文搞懂数据仓库与数据湖
大数据·后端·数据分析
Y004 小时前
PostgreSQL 的锁:为什么你的 ALTER TABLE 会卡住,以及怎么查
数据库·postgresql
大大大大晴天4 小时前
每天认识一个组件:向量化计算加速Apache Auron
大数据
明月_清风4 小时前
数据平台到底是什么?一篇文章搞懂数据平台开发
大数据·后端·数据分析
明月_清风4 小时前
数据是怎么进入数据平台的?一文搞懂数据采集与数据同步
大数据·后端·数据分析
imDwAaY4 小时前
Redo Log 和 Binlog 为什么需要两阶段提交?
后端·mysql
Databend4 小时前
同样 PASS,路径为何不同|用 Jev 逐 Span 评估 Agent Trace
大数据·数据分析·agent