LeetCode 高频 SQL 50 题(基础版)之 【连接】部分 · 上

题目:1378. 使用唯一标识码替换员工ID


题解:

sql 复制代码
select eu.unique_id,e.name from Employees e left join EmployeeUNI eu on e.id=eu.id

题目:1068. 产品销售分析 I



题解:

sql 复制代码
select p.product_name,s.year,s.price from Sales s,Product p 
where s.product_id = p.product_id 

题目:1581. 进店却未进行过交易的顾客




题解:

sql 复制代码
select customer_id,count(customer_id) as count_no_trans from Visits v left join Transactions t on v.visit_id=t.visit_id
where t.transaction_id is null 
group by customer_id
sql 复制代码
select customer_id,count(customer_id) as count_no_trans  from Visits 
where visit_id not in (select distinct visit_id from Transactions )
group by customer_id

题目:197. 上升的温度



题解:

sql 复制代码
select b.id as id from Weather a,Weather b 
where datediff(b.recordDate,a.recordDate)=1 and a.Temperature < b.Temperature

题目:1661. 每台机器的进程平均运行时间




题解:

sql 复制代码
select a.machine_id, round(avg(b.timestamp-a.timestamp),3) as processing_time  from Activity a,Activity b 
where a.machine_id=b.machine_id and a.process_id=b.process_id and a.activity_type='start' and b.activity_type='end'
group by a.machine_id
相关推荐
程序员清风7 小时前
数据处理脚本工程化:日志、配置、命令行与测试
服务器·开发语言·数据库
文丑颜不良啊8 小时前
LeetCode876~900题目解析
java·leetcode
正在走向自律8 小时前
数据集成产品的技术底座:从日志解析原理到 KFS 同步链路搭建(含建表与增删改查完整代码)
数据库·oracle·信创·数据集成·国产数据库·kingbasees·全量+增量同步
程序员塔塔喵8 小时前
【MySQL篇|第七篇】MySQL事务
数据库·mysql·mysql事务
独隅9 小时前
Claude API 实战教程:从入门到完整项目
android·java·数据库·claude·claude code
_孤傲_9 小时前
快速掌握 MySQL 语法
数据库·后端·mysql
数字新视界11 小时前
一体化机柜在数据中心运维中的创新应用与优势分析
大数据·服务器·数据库·动环监控系统·动力与环境监控系统
SelectDB11 小时前
从 StarRocks 走向 Apache Doris:如何实现引擎平滑替换与架构升级?
大数据·数据库·数据分析
为思念酝酿的痛11 小时前
MySQL的操作
数据库·mysql
猫咪很可爱11 小时前
Oracle ORA-4031 错误分析与处理:SGA 内存不足导致 update/exp/expdp 失败
数据库·oracle