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;
相关推荐
yyzc111116 分钟前
AI聚合支付搭配数字门店系统让实体店告别粗放经营
大数据·运维·人工智能
木井巳1 小时前
【动态规划: 子序列问题】最长递增子序列的个数
java·算法·leetcode·动态规划·推荐算法
月夏2 小时前
10 万行全表扫描抓个正着:第一次给 MySQL 加索引
mysql·性能优化
QiLinkOS2 小时前
行业规则的“强制升级”:从“数量竞赛”到“质量博弈”
大数据·人工智能·产业链坐标定位·矩规双螺旋归因模型·矩规评级·科创技术评级·技术坐标刻度模型
FungLeo2 小时前
FengCMS · PHP+MySQL 升级实录 · 数据库驱动封装:mysqli 预处理与 affected_rows 关闭后变 -1 的坑
数据库·mysql·php·工程实践·fengcms
YYYing.3 小时前
【Redis剑指offer系列 (二) 】Redis线程模型
数据库·redis·缓存·八股
风翼靓崽3 小时前
ES综合日志平台搭建
大数据·elasticsearch·搜索引擎
维爱智VR认知学能3 小时前
Python SQLite本地训练记录表迁移失败回滚与事务验证
数据库·python·单元测试·sqlite·软件工程
OpenCSG4 小时前
客户案例|Dell携手OpenCSG打造AI原生超节点
数据库·人工智能·ai-native
TDengine (老段)4 小时前
TDengine IDMP ---- Excel 插件
大数据·数据库·excel·时序数据库·tdengine·涛思数据