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
相关推荐
古月居GYH2 小时前
【数据分析】如何在PyCharm中高效配置和使用SQL
ide·sql·pycharm
JoJo_Way4 小时前
LeetCode三数之和-js题解
javascript·算法·leetcode
计算机毕设定制辅导-无忧学长6 小时前
西门子 PLC 与 Modbus 集成:S7-1500 RTU/TCP 配置指南(一)
服务器·数据库·tcp/ip
凌肖战7 小时前
力扣网C语言编程题:在数组中查找目标值位置之二分查找法
c语言·算法·leetcode
程序员柳7 小时前
基于微信小程序的校园二手交易平台、微信小程序校园二手商城源代码+数据库+使用说明,layui+微信小程序+Spring Boot
数据库·微信小程序·layui
梦在深巷、7 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
IT乌鸦坐飞机7 小时前
ansible部署数据库服务随机启动并创建用户和设置用户有完全权限
数据库·ansible·centos7
IT_10247 小时前
Spring Boot项目开发实战销售管理系统——数据库设计!
java·开发语言·数据库·spring boot·后端·oracle
GEEK零零七9 小时前
Leetcode 1103. 分糖果 II
数学·算法·leetcode·等差数列
祁思妙想9 小时前
八股学习(三)---MySQL
数据库·学习·mysql