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
相关推荐
脑子加油站1 分钟前
Redis数据库基础
数据库·redis·缓存
知识分享小能手2 分钟前
MongoDB入门学习教程,从入门到精通,MongoDB监控完全指南(22)
数据库·学习·mongodb
℡終嚸♂6806 分钟前
SQL 注入与 ThinkPHP 漏洞技术讲义
数据库·sql
杰克尼8 分钟前
redis(day07-Redis 最佳实践)
数据库·redis·缓存
倔强的石头1069 分钟前
表空间自动目录创建与存储管理实践:参数化配置与性能优化
数据库·oracle·性能优化
不剪发的Tony老师9 分钟前
Goose:一款成熟灵活的数据库变更管理工具
数据库
草莓熊Lotso11 分钟前
Linux 线程深度剖析:线程 ID 本质、地址空间布局与 pthread 源码全解
android·linux·运维·服务器·数据库·c++
_日拱一卒15 分钟前
LeetCode:螺旋矩阵
算法·leetcode·矩阵
AcrelGHP17 分钟前
安科瑞AIM-T系列工业IT绝缘监测及故障定位解决方案为关键供电场所筑牢安全防线
大数据·运维·数据库
fīɡЙtīиɡ ℡18 分钟前
【Mysql——MVCC】
数据库·mysql