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;
相关推荐
爱coding的橙子3 分钟前
Day87:2.12:leetcode 动态规划8道题,用时3h
算法·leetcode·动态规划
TongSearch13 分钟前
Tongsearch分片的分配、迁移与生命周期管理
java·服务器·数据库·elasticsearch·tongsearch
龙山云仓17 分钟前
No152:AI中国故事-对话祖冲之——圆周率与AI精度:数学直觉与极限探索
大数据·开发语言·人工智能·python·机器学习
云境天合小科普19 分钟前
无人机用能见度检测仪:预测能见度骤降风险
大数据
跨境小技24 分钟前
2026 Shopee数据抓取逐步教程:技术难点、解决思路与实战方法
前端·数据库·网络爬虫
一个天蝎座 白勺 程序猿27 分钟前
Apache IoTDB(14):IoTDB结果集排序与查询对齐模式——ORDER BY与ALIGN BY DEVICE使用
大数据·ai·apache·时序数据库·iotdb
一个天蝎座 白勺 程序猿31 分钟前
Apache IoTDB(9):数据库操作——数据写入从CLI到集群部署的六种实战
数据库·apache·时序数据库·iotdb
heimeiyingwang38 分钟前
官网知识库结构化整理指南
java·sql·架构·database
l1t42 分钟前
DeepSeek总结的数据库性能教学文章
网络·数据库·oracle
认真的薛薛42 分钟前
数据库-redis与mongo
数据库·mysql