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
相关推荐
lkbhua莱克瓦242 分钟前
进阶-SQL优化
java·数据库·sql·mysql·oracle
石小千4 分钟前
Myql binlog反向解析成sql
数据库·sql
alonewolf_9911 分钟前
MySQL 8.0 主从复制原理深度剖析与实战全解(异步、半同步、GTID、MGR)
数据库·mysql·adb
Swift社区16 分钟前
LeetCode 472 连接词
算法·leetcode·职场和发展
Dream it possible!18 分钟前
LeetCode 面试经典 150_二分查找_搜索旋转排序数组(114_33_C++_中等)
c++·leetcode·面试
八九燕来20 分钟前
django + drf 多表关联场景下的序列化器选型与实现逻辑
数据库·django·sqlite
Mr. Cao code29 分钟前
MySQL数据卷实战:持久化存储秘籍
数据库·mysql·docker·容器
小北方城市网30 分钟前
微服务架构设计实战指南:从拆分到落地,构建高可用分布式系统
java·运维·数据库·分布式·python·微服务
爱喝水的鱼丶33 分钟前
SAP-ABAP:SAP性能侦探:STAD事务码的深度解析与应用实战
开发语言·数据库·学习·sap·abap