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;
相关推荐
程序员佳佳10 分钟前
2025年大模型终极横评:GPT-5.2、Banana Pro与DeepSeek V3.2实战硬核比拼(附统一接入方案)
服务器·数据库·人工智能·python·gpt·api
qq_124987075321 分钟前
重庆三峡学院图书资料管理系统设计与实现(源码+论文+部署+安装)
java·spring boot·后端·mysql·spring·毕业设计
大学生资源网25 分钟前
java毕业设计之“知语”花卉销售网站的设计与实现源码(源代码+文档)
java·mysql·毕业设计·源码·springboot
roo_134 分钟前
github 获取构造图数据库的LNB数据集和使用说明
数据库
XFF不秃头1 小时前
力扣刷题笔记-全排列
c++·笔记·算法·leetcode
菜鸟233号1 小时前
力扣669 修剪二叉搜索树 java实现
java·数据结构·算法·leetcode
罗汉松驻扎的工作基地1 小时前
sql server 2014 下载和安装
数据库
yaoh.wang2 小时前
力扣(LeetCode) 100: 相同的树 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
SadSunset2 小时前
力扣题目142. 环形链表 II的解法分享,附图解
算法·leetcode·链表
<花开花落>2 小时前
Cursor 的 MCP 应用:mysql-mcp-server
mysql·cursor·mcp