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
相关推荐
User_芊芊君子6 分钟前
C语言循环结构实战:while和for到底用哪个?
android·c语言·数据库
哈哈的二哈8 分钟前
MySql--explain的用法
数据库·mysql
superonion062010 分钟前
【DB2】ERRORCODE=-4499, SQLSTATE=08001
数据库
Gauss松鼠会15 分钟前
GaussDB安全配置最佳实践:构建企业级数据防护体系
数据库·sql·安全·性能优化·database·gaussdb
Sherlock Ma24 分钟前
MySQL:零基础入门(狂神版)
java·数据库·程序人生·mysql·职场和发展·学习方法·改行学it
悦数图数据库31 分钟前
Web3 风控挑战重重,图数据库为何成为破局关键-悦数图数据库
数据库·web3
绿龙术士35 分钟前
.NET ORM开发手册:基于SqlSugar的高效数据访问全攻略
sql·c#·.net
青临的踩坑之路43 分钟前
Spring Boot事务失效场景及解决方案
数据库·spring boot·sql
心想好事成1 小时前
尚硅谷redis7 63-69 redis哨兵监控之理论简介
数据库·redis·缓存
I AM_SUN1 小时前
153. 寻找旋转排序数组中的最小值
数据结构·c++·算法·leetcode·二分法