LeetCode(sql)-0723

news/2024/11/29 0:55:43/

聚合函数

620

select * 
from cinema
where mod(id,2)=1 and description <> 'boring'
order by rating desc

1251

select p.product_id,
Round(sum(price*units)/sum(units),2)as average_price
from UnitsSold u left join Prices p
using(product_id)
where purchase_date <= end_date and purchase_date >= start_date
group by product_id

1075

round 函数保留小数位

select project_id,
Round(sum(experience_years)/count(*),2) as average_years
from Project left join Employee
using(employee_id)
group by project_id

排序和分组

2356

select teacher_id,count(DISTINCT subject_id)as cnt
from Teacher
group by teacher_id 

1141

select activity_date as day,
count(distinct user_id) as active_users
from Activity
where DateDiff('2019-07-27',activity_date) < 30
and DateDiff('2019-07-27',activity_date) >= 0
group by activity_date

1084

SELECT product_id, product_name
FROM Product
WHERE product_id NOT IN (SELECT product_idFROM SalesWHERE '2019-01-01' > sale_date OR sale_date > '2019-03-31'
)
AND product_id IN (SELECT product_idFROM SalesWHERE '2019-01-01' <= sale_date AND sale_date <= '2019-03-31'
);

高级查询和连接

1731

SELECT employee_id, name, reports_count, average_age
FROM (SELECT reports_to,COUNT(DISTINCT employee_id) AS reports_count,ROUND(AVG(age), 0) AS average_ageFROM EmployeesWHERE reports_to IS NOT NULLGROUP BY reports_to
) r
LEFT JOIN Employees e ON e.employee_id = r.reports_to;

子查询

1978

SELECT employee_id
FROM Employees
WHERE manager_id NOT IN (SELECT employee_idFROM Employees
)
AND salary < 30000
ORDER BY employee_id ASC;

高级字符串函数 / 正则表达式 / 子句

1667

concat函数

select user_id,
Concat(Upper(Left(name,1)),Lower(Right(name,Length(name)-1))) as name
from Users
order by user_id

1527

select patient_id,patient_name,conditions from Patients
where conditions like 'DIAB1%' or conditions like '% DIAB1%'

http://www.ppmy.cn/news/978015.html

相关文章

MURF20100CT-ASEMI快恢复对管20A 1000V

编辑&#xff1a;ll MURF20100CT-ASEMI快恢复对管20A 1000V 型号&#xff1a;MURF20100CT 品牌&#xff1a;ASEMI 封装&#xff1a;TO-220F 恢复时间&#xff1a;50ns 正向电流&#xff1a;20A 反向耐压&#xff1a;1000V 芯片大小&#xff1a;102MIL*2 芯片个数&…

elasticsearch查询操作(DSL语句方式)

说明&#xff1a;本文介绍在kibana&#xff0c;es的可视化界面上对文档的查询操作&#xff1b; 添加数据 先使用API&#xff0c;创建索引库&#xff0c;并且把数据从MySQL中查出来&#xff0c;传到ES上&#xff0c;参考&#xff08;http://t.csdn.cn/NaTHg&#xff09; 索引库…

SELFIES中的函数简介

import selfies as sf 点进入selfies&#xff0c;可以看到inti中有如下方法&#xff1a; 1、"encoder", >>> import selfies as sf >>> sf.encoder("CCF") [C][C][F] 2、"decoder", >>> import selfies as sf >…

Spring-缓存初步认识

Spring-缓存 简单介绍 缓存是一种介于数据永久存储介质和数据应用之间的数据临时存储介质缓存有效提高读取速度&#xff0c;加速查询效率 spring使用缓存方式 添加依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring…

什么是RESTful API

什么是RESTful API RESTful API是利用HTTP请求访问或使用数据的应用程序接口&#xff08;API&#xff09;的体系结构样式。这些数据可用于GET&#xff0c;PUT&#xff0c;POST和DELETE数据类型&#xff0c;这些数据类型指的是与资源相关的操作读取、更新、创建和删除。 网站的…

vue项目docker docker-compose 本地开发环境配置

配置Docker Compose用于在本地开发Vue项目是一个方便且高效的方法。Docker Compose允许您定义和管理多个容器组成的应用程序。 一、配置Docker Compose文件&#xff0c;用于在本地开发Vue项目 docker-compose.yaml version: 3 services:# Vue应用容器vue-app:build:context: …

代码随想录day12 | [前、中、后、层]二叉树的遍历迭代法和递归法

文章目录 一、前后中序递归法二、前后序迭代法三、中序遍历迭代法四、层序遍历 递归三部曲&#xff1a; 1️⃣ 第一步确定递归函数的返回值和参数 2️⃣第二步确定递归的终止条件 3️⃣第三步确定单层递归处理的逻辑 一、前后中序递归法 前序遍历二叉树 class Solution { pr…

Spring Boot单元测试入门指南

Spring Boot单元测试入门指南 JUnit是一个成熟和广泛应用的Java单元测试框架&#xff0c;它提供了丰富的功能和灵活的扩展机制&#xff0c;可以帮助开发人员编写高质量的单元测试。通过JUnit&#xff0c;开发人员可以更加自信地进行重构、维护和改进代码&#xff0c;同时提高代…