MySQL-复杂SQL语句编写:子查询分析与练习

子查询

    • 1. 由一个具体的需求,引入子查询
    • 2. 称谓的规范:外查询(或主查询)、内查询(或子查询)
    • 3. 子查询的分类
    • 4. 单行子查询
      • 4.1 单行操作符: = != > >= < <=
      • 4.2 子查询中的空值问题
      • 4.3 非法使用子查询
    • 5.多行子查询
      • 5.1 多行子查询的操作符: IN ANY ALL SOME(同ANY)
      • 5.2举例:
      • 5.3 空值问题(存在记录行为null,会导致没有结果)
    • 6. 相关子查询
      • 6.1 子查询可以出现的位置
      • 6.2 EXISTS 与 NOT EXISTS关键字
  • 子查询的练习
    • 1.查询和Zlotkey相同部门的员工姓名和工资
    • 2.查询工资比公司平均工资高的员工的员工号,姓名和工资。
    • 3.选择工资大于所有JOB_ID = 'SA_MAN'的员工的工资的员工的last_name, job_id, salary
    • 4.查询和姓名中包含字母u的员工在相同部门的员工的员工号和姓名
    • 5.查询在部门的location_id为1700的部门工作的员工的员工号
    • 6.查询管理者是King的员工姓名和工资
    • 7.查询工资最低的员工信息: last_name, salary
    • 8.查询平均工资最低的部门信息
    • 9.查询平均工资最低的部门信息和该部门的平均工资(相关子查询)
    • 10.查询平均工资最高的 job 信息
    • 11.查询平均工资高于公司平均工资的部门有哪些?
    • 12.查询出公司中所有 manager 的详细信息
    • 13.各个部门中 最高工资中最低的那个部门的 最低工资是多少?
    • 14.查询平均工资最高的部门的 manager 的详细信息: last_name, department_id, email, salary
    • 15. 查询部门的部门号,其中不包括job_id是"ST_CLERK"的部门号
    • 16. 选择所有没有管理者的员工的last_name
    • 17.查询员工号、姓名、雇用时间、工资,其中员工的管理者为 'De Haan'
    • 18.查询各部门中工资比本部门平均工资高的员工的员工号, 姓名和工资(相关子查询)
    • 19.查询每个部门下的部门人数大于 5 的部门名称(相关子查询)
    • 20.查询每个国家下的部门个数大于 2 的国家编号(相关子查询)

1. 由一个具体的需求,引入子查询

需求:谁的工资比Abel的高?

#方式1:
SELECT salary
FROM employees
WHERE last_name = 'Abel';SELECT last_name,salary
FROM employees
WHERE salary > 11000;#方式2:自连接
SELECT e2.last_name,e2.salary
FROM employees e1,employees e2
WHERE e2.`salary` > e1.`salary` #多表的连接条件
AND e1.last_name = 'Abel';#方式3:子查询
SELECT last_name,salary
FROM employees
WHERE salary > (SELECT salaryFROM employeesWHERE last_name = 'Abel');

2. 称谓的规范:外查询(或主查询)、内查询(或子查询)

  • 子查询(内查询)在主查询之前一次执行完成。
  • 子查询的结果被主查询(外查询)使用 。
  • 注意事项
    • 子查询要包含在括号内
    • 将子查询放在比较条件的右侧
    • 单行操作符对应单行子查询,多行操作符对应多行子查询

不推荐:

SELECT last_name,salary
FROM employees
WHERE  (SELECT salaryFROM employeesWHERE last_name = 'Abel') < salary;

3. 子查询的分类

角度1:从内查询返回的结果的条目数
单行子查询 vs 多行子查询

角度2:内查询是否被执行多次
相关子查询 vs 不相关子查询

比如:相关子查询的需求:查询工资大于本部门平均工资的员工信息。
不相关子查询的需求:查询工资大于本公司平均工资的员工信息。

子查询的编写技巧(或步骤):① 从里往外写 ② 从外往里写

4. 单行子查询

4.1 单行操作符: = != > >= < <=

题目:查询工资大于149号员工工资的员工的信息

SELECT employee_id,last_name,salary
FROM employees
WHERE salary > (SELECT salaryFROM employeesWHERE employee_id = 149);

题目:返回job_id与141号员工相同,salary比143号员工多的员工姓名,job_id和工资

SELECT last_name,job_id,salary
FROM employees
WHERE job_id = (SELECT job_idFROM employeesWHERE employee_id = 141)
AND salary > (SELECT salaryFROM employeesWHERE employee_id = 143);

题目:返回公司工资最少的员工的last_name,job_id和salary

SELECT last_name,job_id,salary
FROM employees
WHERE salary = (SELECT MIN(salary)FROM employees);

题目:查询与141号员工的manager_id和department_id相同的其他员工的employee_id,manager_id,department_id。

#方式1:
SELECT employee_id,manager_id,department_id
FROM employees
WHERE manager_id = (SELECT manager_idFROM employeesWHERE employee_id = 141)
AND department_id = (SELECT department_idFROM employeesWHERE employee_id = 141)
AND employee_id <> 141;#方式2:了解
SELECT employee_id,manager_id,department_id
FROM employees
WHERE (manager_id,department_id) = (SELECT manager_id,department_idFROM employeesWHERE employee_id = 141)
AND employee_id <> 141;

题目:查询最低工资大于110号部门最低工资的部门id和其最低工资

SELECT department_id,MIN(salary)
FROM employees
WHERE department_id IS NOT NULL
GROUP BY department_id
HAVING MIN(salary) > (SELECT MIN(salary)FROM employeesWHERE department_id = 110);

题目:显式员工的employee_id,last_name和location。其中,若员工department_id与location_id为1800的department_id相同,则location为’Canada’,其余则为’USA’。

SELECT employee_id,last_name,CASE department_id WHEN (SELECT department_id FROM departments WHERE location_id = 1800) THEN 'Canada'ELSE 'USA' END "location"
FROM employees;

4.2 子查询中的空值问题

SELECT last_name, job_id
FROM   employees
WHERE  job_id =(SELECT job_idFROM   employeesWHERE  last_name = 'Haas');

4.3 非法使用子查询

错误:Subquery returns more than 1 row
– 子查询有多个结果

SELECT employee_id, last_name
FROM   employees
WHERE  salary =(SELECT   MIN(salary)FROM     employeesGROUP BY department_id);         

5.多行子查询

5.1 多行子查询的操作符: IN ANY ALL SOME(同ANY)

5.2举例:

IN

SELECT employee_id, last_name
FROM   employees
WHERE  salary IN(SELECT   MIN(salary)FROM     employeesGROUP BY department_id); 

ANY / ALL
题目:返回其它job_id中比job_id为‘IT_PROG’部门任一工资低的员工的员工号、姓名、job_id 以及salary

SELECT employee_id,last_name,job_id,salary
FROM employees
WHERE job_id <> 'IT_PROG'
AND salary < ANY (SELECT salaryFROM employeesWHERE job_id = 'IT_PROG');

题目:返回其它job_id中比job_id为‘IT_PROG’部门所有工资低的员工的员工号、姓名、job_id 以及salary

SELECT employee_id,last_name,job_id,salary
FROM employees
WHERE job_id <> 'IT_PROG'
AND salary < ALL (SELECT salaryFROM employeesWHERE job_id = 'IT_PROG');

题目:查询平均工资最低的部门id
MySQL中聚合函数是不能嵌套使用的。

#方式1:
SELECT department_id
FROM employees
GROUP BY department_id
HAVING AVG(salary) = (SELECT MIN(avg_sal)FROM(SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal);#方式2:
SELECT department_id
FROM employees
GROUP BY department_id
HAVING AVG(salary) <= ALL(	SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id) 

5.3 空值问题(存在记录行为null,会导致没有结果)

SELECT last_name
FROM employees
WHERE employee_id NOT IN (-- 改为 in 的时候,由于employee_id是主键,所以不会为null,所以没有报错SELECT manager_idFROM employees);

6. 相关子查询

回顾:查询员工中工资大于公司平均工资的员工的last_name,salary和其department_id

6.1 子查询可以出现的位置

SELECT last_name,salary,department_id
FROM employees
WHERE salary > (SELECT AVG(salary)FROM employees);

题目:查询员工中工资大于本部门平均工资的员工的last_name,salary和其department_id

#方式1:使用相关子查询,where中子查询
SELECT last_name,salary,department_id
FROM employees e1
WHERE salary > (SELECT AVG(salary)FROM employees e2WHERE department_id = e1.`department_id`);#方式2:在FROM中声明子查询,采用临时表
SELECT e.last_name,e.salary,e.department_id
FROM employees e,(SELECT department_id,AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal
WHERE e.department_id = t_dept_avg_sal.department_id
AND e.salary > t_dept_avg_sal.avg_sal

题目:查询员工的id,salary,按照department_name 排序

SELECT employee_id,salary
FROM employees e
ORDER BY (SELECT department_nameFROM departments dWHERE e.`department_id` = d.`department_id`) ASC;

结论:在SELECT中,除了GROUP BY 和 LIMIT之外,其他位置都可以声明子查询!

SELECT ....,....,....(存在聚合函数)
FROM ... (LEFT / RIGHT)JOIN ....ON 多表的连接条件 
(LEFT / RIGHT)JOIN ... ON ....
WHERE 不包含聚合函数的过滤条件
GROUP BY ...,....
HAVING 包含聚合函数的过滤条件
ORDER BY ....,...(ASC / DESC )
LIMIT ...,....

题目:若employees表中employee_id与job_history表中employee_id相同的数目不小于2,输出这些相同id的员工的employee_id,last_name和其job_id

SELECT *
FROM job_history;SELECT employee_id,last_name,job_id
FROM employees e
WHERE 2 <= (SELECT COUNT(*)FROM job_history jWHERE e.`employee_id` = j.`employee_id`)

6.2 EXISTS 与 NOT EXISTS关键字

题目:查询公司管理者的employee_id,last_name,job_id,department_id信息

#方式1:自连接
SELECT DISTINCT mgr.employee_id,mgr.last_name,mgr.job_id,mgr.department_id
FROM employees emp JOIN employees mgr
ON emp.manager_id = mgr.employee_id;#方式2:子查询
SELECT employee_id,last_name,job_id,department_id
FROM employees
WHERE employee_id IN (SELECT DISTINCT manager_idFROM employees);#方式3:使用EXISTS
SELECT employee_id,last_name,job_id,department_id
FROM employees e1
WHERE EXISTS (-- 查到为止,没查到,会继续往下面查SELECT *FROM employees e2WHERE e1.`employee_id` = e2.`manager_id`);

题目:查询departments表中,不存在于employees表中的部门的department_id和department_name

#方式1:
SELECT d.department_id,d.department_name
FROM employees e RIGHT JOIN departments d
ON e.`department_id` = d.`department_id`
WHERE e.`department_id` IS NULL;
-- or  下面的更容易理解
SELECT d.department_id,d.department_name
FROM departments d left JOIN employees e
ON e.`department_id` = d.`department_id`
WHERE e.`department_id` IS NULL;#方式2:
SELECT department_id,department_name
FROM departments d
WHERE NOT EXISTS (SELECT *FROM employees eWHERE d.`department_id` = e.`department_id`);SELECT COUNT(*)
FROM departments;

子查询的练习

1.查询和Zlotkey相同部门的员工姓名和工资

SELECT last_name,salary
FROM employees
WHERE department_id IN (SELECT department_idFROM employeesWHERE last_name = 'Zlotkey');

2.查询工资比公司平均工资高的员工的员工号,姓名和工资。

SELECT employee_id,last_name,salary
FROM employees
WHERE salary > (SELECT AVG(salary)FROM employees);

3.选择工资大于所有JOB_ID = 'SA_MAN’的员工的工资的员工的last_name, job_id, salary

SELECT last_name,job_id,salary
FROM employees
WHERE salary > ALL(SELECT salaryFROM employeesWHERE job_id = 'SA_MAN');

4.查询和姓名中包含字母u的员工在相同部门的员工的员工号和姓名

SELECT employee_id,last_name
FROM employees 
WHERE department_id IN (SELECT DISTINCT department_idFROM employeesWHERE last_name LIKE '%u%');

5.查询在部门的location_id为1700的部门工作的员工的员工号

SELECT employee_id
FROM employees
WHERE department_id IN (SELECT department_idFROM departmentsWHERE location_id = 1700);

6.查询管理者是King的员工姓名和工资

SELECT last_name,salary,manager_id
FROM employees
WHERE manager_id IN (SELECT employee_idFROM employeesWHERE last_name = 'King');

7.查询工资最低的员工信息: last_name, salary

SELECT last_name,salary
FROM employees
WHERE salary = (SELECT MIN(salary)FROM employees);

8.查询平均工资最低的部门信息

#方式1:
SELECT *
FROM departments
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) = (SELECT MIN(avg_sal)FROM (SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal));
#方式2:
SELECT *
FROM departments
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) <= ALL(SELECT AVG(salary)FROM employeesGROUP BY department_id));#方式3: LIMIT
SELECT *
FROM departments
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) =(SELECT AVG(salary) avg_salFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 1		));#方式4:
SELECT d.*
FROM departments d,(SELECT department_id,AVG(salary) avg_salFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 0,1) t_dept_avg_sal
WHERE d.`department_id` = t_dept_avg_sal.department_id

9.查询平均工资最低的部门信息和该部门的平均工资(相关子查询)

#方式1:
SELECT d.*,(SELECT AVG(salary) FROM employees WHERE department_id = d.`department_id`) avg_sal
FROM departments d
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) = (SELECT MIN(avg_sal)FROM (SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal));#方式2:
SELECT d.*,(SELECT AVG(salary) FROM employees WHERE department_id = d.`department_id`) avg_sal
FROM departments d
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) <= ALL(SELECT AVG(salary)FROM employeesGROUP BY department_id));#方式3: LIMIT
SELECT d.*,(SELECT AVG(salary) FROM employees WHERE department_id = d.`department_id`) avg_sal
FROM departments d
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary ) =(SELECT AVG(salary) avg_salFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 1		));#方式4:
SELECT d.*,(SELECT AVG(salary) FROM employees WHERE department_id = d.`department_id`) avg_sal
FROM departments d,(SELECT department_id,AVG(salary) avg_salFROM employeesGROUP BY department_idORDER BY avg_sal ASCLIMIT 0,1) t_dept_avg_sal
WHERE d.`department_id` = t_dept_avg_sal.department_id

10.查询平均工资最高的 job 信息

#方式1:
SELECT *
FROM jobs
WHERE job_id = (SELECT job_idFROM employeesGROUP BY job_idHAVING AVG(salary) = (SELECT MAX(avg_sal)FROM (SELECT AVG(salary) avg_salFROM employeesGROUP BY job_id) t_job_avg_sal));#方式2:
SELECT *
FROM jobs
WHERE job_id = (SELECT job_idFROM employeesGROUP BY job_idHAVING AVG(salary) >= ALL(SELECT AVG(salary) FROM employeesGROUP BY job_id));#方式3:
SELECT *
FROM jobs
WHERE job_id = (SELECT job_idFROM employeesGROUP BY job_idHAVING AVG(salary) =(SELECT AVG(salary) avg_salFROM employeesGROUP BY job_idORDER BY avg_sal DESCLIMIT 0,1));#方式4:
SELECT j.*
FROM jobs j,(SELECT job_id,AVG(salary) avg_salFROM employeesGROUP BY job_idORDER BY avg_sal DESCLIMIT 0,1		) t_job_avg_sal
WHERE j.job_id = t_job_avg_sal.job_id

11.查询平均工资高于公司平均工资的部门有哪些?

SELECT department_id
FROM employees
WHERE department_id IS NOT NULL
GROUP BY department_id
HAVING AVG(salary) > (SELECT AVG(salary)FROM employees);

12.查询出公司中所有 manager 的详细信息

#方式1:自连接  xxx worked for yyy
SELECT DISTINCT mgr.employee_id,mgr.last_name,mgr.job_id,mgr.department_id
FROM employees emp JOIN employees mgr
ON emp.manager_id = mgr.employee_id;#方式2:子查询SELECT employee_id,last_name,job_id,department_id
FROM employees
WHERE employee_id IN (SELECT DISTINCT manager_idFROM employees);#方式3:使用EXISTS
SELECT employee_id,last_name,job_id,department_id
FROM employees e1
WHERE EXISTS (SELECT *FROM employees e2WHERE e1.`employee_id` = e2.`manager_id`);

13.各个部门中 最高工资中最低的那个部门的 最低工资是多少?

#方式1:
SELECT MIN(salary)
FROM employees
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING MAX(salary) = (SELECT MIN(max_sal)FROM (SELECT MAX(salary) max_salFROM employeesGROUP BY department_id) t_dept_max_sal));SELECT *
FROM employees
WHERE department_id = 10;#方式2:
SELECT MIN(salary)
FROM employees
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING MAX(salary) <= ALL (SELECT MAX(salary)FROM employeesGROUP BY department_id));#方式3:
SELECT MIN(salary)
FROM employees
WHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING MAX(salary) = (SELECT MAX(salary) max_salFROM employeesGROUP BY department_idORDER BY max_sal ASCLIMIT 0,1));#方式4:
SELECT MIN(salary)
FROM employees e,(SELECT department_id,MAX(salary) max_salFROM employeesGROUP BY department_idORDER BY max_sal ASCLIMIT 0,1) t_dept_max_sal
WHERE e.department_id = t_dept_max_sal.department_id

14.查询平均工资最高的部门的 manager 的详细信息: last_name, department_id, email, salary

#方式1:
SELECT last_name, department_id, email, salary
FROM employees
WHERE employee_id = ANY (SELECT DISTINCT manager_idFROM employeesWHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary) = (SELECT MAX(avg_sal)FROM (SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal)));#方式2:
SELECT last_name, department_id, email, salary
FROM employees
WHERE employee_id = ANY (SELECT DISTINCT manager_idFROM employeesWHERE department_id = (SELECT department_idFROM employeesGROUP BY department_idHAVING AVG(salary) >= ALL (SELECT AVG(salary) avg_salFROM employeesGROUP BY department_id)));#方式3:
SELECT last_name, department_id, email, salary
FROM employees
WHERE employee_id IN (SELECT DISTINCT manager_idFROM employees e,(SELECT department_id,AVG(salary) avg_salFROM employeesGROUP BY department_idORDER BY avg_sal DESCLIMIT 0,1) t_dept_avg_salWHERE e.`department_id` = t_dept_avg_sal.department_id);

15. 查询部门的部门号,其中不包括job_id是"ST_CLERK"的部门号

#方式1:
SELECT department_id
FROM departments
WHERE department_id NOT IN (SELECT DISTINCT department_idFROM employeesWHERE job_id = 'ST_CLERK');#方式2:
SELECT department_id
FROM departments d
WHERE NOT EXISTS (SELECT *FROM employees eWHERE d.`department_id` = e.`department_id`AND e.`job_id` = 'ST_CLERK');

16. 选择所有没有管理者的员工的last_name

SELECT last_name
FROM employees emp
WHERE NOT EXISTS (SELECT *FROM employees mgrWHERE emp.`manager_id` = mgr.`employee_id`);

17.查询员工号、姓名、雇用时间、工资,其中员工的管理者为 ‘De Haan’

#方式1:
SELECT employee_id,last_name,hire_date,salary
FROM employees
WHERE manager_id IN (SELECT employee_idFROM employeesWHERE last_name = 'De Haan');#方式2:
SELECT employee_id,last_name,hire_date,salary
FROM employees e1
WHERE EXISTS (SELECT *FROM employees e2WHERE e1.`manager_id` = e2.`employee_id`AND e2.last_name = 'De Haan'); 

18.查询各部门中工资比本部门平均工资高的员工的员工号, 姓名和工资(相关子查询)

#方式1:使用相关子查询
SELECT last_name,salary,department_id
FROM employees e1
WHERE salary > (SELECT AVG(salary)FROM employees e2WHERE department_id = e1.`department_id`);#方式2:在FROM中声明子查询
SELECT e.last_name,e.salary,e.department_id
FROM employees e,(SELECT department_id,AVG(salary) avg_salFROM employeesGROUP BY department_id) t_dept_avg_sal
WHERE e.department_id = t_dept_avg_sal.department_id
AND e.salary > t_dept_avg_sal.avg_sal

19.查询每个部门下的部门人数大于 5 的部门名称(相关子查询)

SELECT department_name
FROM departments d
WHERE 5 < (SELECT COUNT(*)FROM employees eWHERE d.department_id = e.`department_id`);

20.查询每个国家下的部门个数大于 2 的国家编号(相关子查询)

SELECT * FROM locations;SELECT country_id
FROM locations l
WHERE 2 < (SELECT COUNT(*)FROM departments dWHERE l.`location_id` = d.`location_id`);

子查询的编写技巧(或步骤):① 从里往外写 ② 从外往里写

如何选择?
① 如果子查询相对较简单,建议从外往里写。一旦子查询结构较复杂,则建议从里往外写
② 如果是相关子查询的话,通常都是从外往里写。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/799438.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

揭开Spring Bean生命周期的神秘面纱

目录 一、Spring IOC 1.1 Spring IOC 的加载过程 二、Spring Bean 生命周期 2.1 实例化前置 2.2 实例化后置 2.3 属性赋值 2.4 初始化前置 2.5 初始化 2.6 初始化后置 2.7 Bean 销毁 Spring 是一个开源的企业级Java应用程序框架&#xff0c;它简化了企业级应用程序开…

开源数据湖iceberg, hudi ,delta lake, paimon对比分析

Iceberg, Hudi, Delta Lake和Paimon都是用于大数据湖(Data Lake)或数据仓库(Data Warehouse)中数据管理和处理的工具或框架,但它们在设计、功能和适用场景上有所不同。 Iceberg: Iceberg是用于大型分析表的高性能格式。Iceberg将SQL表的可靠性和简易性带入到大数据领域,同…

【java的本地锁到分布式锁介绍】

文章目录 1.java本地自带锁介绍及应用synchronized&#xff08;1&#xff09;synchronized原理和优化&#xff08;2&#xff09;synchronized作用&#xff08;3&#xff09;synchronized的使用 CAS(1) CAS原理&#xff08;2&#xff09;CAS和synchronized优缺点 lock 2.分布式锁…

idea常用配置

IDEA设置全局配置 参考&#xff1a;IDEA设置全局配置_idea如何打开一个项目,全局设置-CSDN博客 idea提交代码到git或svn上时&#xff0c;怎么忽略.class、.iml文件和文件夹等不必要的文件 参考&#xff1a;idea提交代码到git或svn上时&#xff0c;怎么忽略.class、.iml文件和文…

LeetCode-74. 搜索二维矩阵【数组 二分查找 矩阵】

LeetCode-74. 搜索二维矩阵【数组 二分查找 矩阵】 题目描述&#xff1a;解题思路一&#xff1a;先二分查找行&#xff0c;再二分查找列。解题思路二&#xff1a;暴力遍历&#xff0c;也能过。解题思路三&#xff1a;用python的in。 题目描述&#xff1a; 给你一个满足下述两条…

VSCODE目录树缩进调整

VSCode默认的缩进太小了&#xff0c;简直看不出来&#xff0c;很容易弄混目录。在设置里修改就行了。 修改后效果&#xff1a;

何为网络协议?一图知晓网络过程。

网络协议就是计算机之间沟通的语言 为了有效地交流&#xff0c;计算机之间需要一种共同的规则或协议&#xff0c; 就像我们和老外沟通之前&#xff0c;要先商量好用哪种语言&#xff0c; 要么大家都说中文&#xff0c;要么大家都说英语&#xff0c;这才能有效地沟通。 网络协…

04-springmvc-RequestContextHolder

一、获取request对象的四种方法 方法1、Controller中加参数来获取request 注意&#xff1a;只能在Controller中加入request参数。 一般&#xff0c;我们在Controller中加参数获取HttpServletRequest&#xff0c;如下所示&#xff1a; RestController RequestMapping("…

OSPF中配置静态路由负载分担实验简述

OSPF中配置静态路由负载分担 实验简述 在静态路由负载分担中&#xff0c;多个路由器被配置为共享负载的目标&#xff0c;以实现流量的均衡分配。 到达目的地有N条相同度量值的路径&#xff0c;默认值60&#xff0c;N条路由是等价路由&#xff0c;数据报文在N条链路上轮流发送。…

速盾:cdn原服务器地理位置

CDN&#xff08;Content Delivery Network&#xff09;是一种通过在不同地理位置部署服务器的技术&#xff0c;旨在提高网站的访问速度和稳定性。它将原始服务器内容复制到多个节点服务器中&#xff0c;这些节点服务器分布在全球各个地理位置&#xff0c;并根据用户的地理位置和…

使用iPhone/安卓手机代替门禁卡

文章目录 基础知识ID卡和IC卡ID卡技术IC卡技术IC卡加密方式手机NFC只能模拟IC卡&#xff0c;而不支持ID卡电梯卡可能使用滚动码验证方式&#xff0c;不支持使用手机模拟 &#xff08;IC类型&#xff09;门禁卡验证方式仅验证ID&#xff08;卡号&#xff09;验证ID分区信息 iPho…

【云开发笔记NO.28】数据中台的概述

数据中台的定义 在云开发中&#xff0c;数据中台是一个综合性的数据管理和服务平台&#xff0c;它集成了数据管理、数据治理、数据服务等多个功能&#xff0c;并基于云计算技术架构而建立。数据中台的核心目标是为企业提供稳定、高效、安全的数据支持和服务&#xff0c;进而推…

探索基于WebRTC的有感录屏技术开发流程

title: 探索基于WebRTC的有感录屏技术开发流程 date: 2024/4/7 18:21:56 updated: 2024/4/7 18:21:56 tags: WebRTC录屏技术屏幕捕获有感录屏MediaStream实时传输音频录制 第一章&#xff1a;技术原理 WebRTC&#xff08;Web Real-Time Communication&#xff09;是一种开放源…

Python中的 if __name__ == ‘__main__‘

一、if name ‘main’ 在Python的世界里&#xff0c;if name ‘main’:这行代码就像是派对的入口&#xff0c;它决定了哪些部分是只在当前这个“派对”&#xff08;或者说脚本&#xff09;中直接执行的&#xff0c;哪些部分是可以被其他“派对”&#xff08;或脚本&#xff…

【Vue】 Vue项目中的跨域配置指南

她坐红帐 面带浓妆 唢呐一声唱 明月光 这女子泪眼拜高堂 一拜天地日月 二拜就遗忘这一生 跪三拜红尘凉 庭院 大门锁上 杂乱的眼光 多喧嚷 这女子笑颜几惆怅 余生喜乐悲欢都无关 她眼中已无光 &#x1f3b5; 倪莫问《三拜红尘凉》 在前后端分离的项目开发中…

Java中的内存模型和例子

Java内存模型&#xff08;Java Memory Model, JMM&#xff09;是Java虚拟机&#xff08;JVM&#xff09;规范中定义的一种关于内存访问、共享变量在多线程之间的可见性、以及原子性、顺序性的规则。Java内存模型的目标是定义程序中各个共享变量的访问方式&#xff0c;以及如何在…

python实例1.2:创建一个简易的命令行地址簿程序,允许用户添加、删除、查找和编辑联系人(详解及其知识点拓展)

目录 一、基础&#xff1a;地址簿程序代码附带注释 二、基础&#xff1a;地址簿程序详细分析 三、拓展&#xff1a;地址簿程序拓展&#xff0c;如何实现在地址簿程序中持久化数据&#xff1f; 四、拓展&#xff1a;地址簿程序拓展代码详细分析 一、基础&#xff1a;地址簿程…

SQL Sever 2008 安装教程

先从官网下载程序&#xff1a;下载地址 打开上述链接后&#xff0c;点击下载按钮。 就会跳出下面这个界面&#xff0c;如果你的电脑是64位的请选择下图中这两个程序。 下载完成后&#xff0c;在电脑磁盘中找到这两个文件&#xff0c;注意安装的顺序&#xff0c;先安装 SQLEXPR…

Linux:软硬链接及动静态库

一、Linux中的链接文件 1.1硬链接及应用场景 ln//创建硬链接 我们再创建一个硬链接生成的文件。 我们可以看到mlink.hard的inode和makefile.c的inode都是一样的&#xff0c;inode一样里面的数据自然也是一样。相当于对make.file进行了一个重命名&#xff0c;所以硬链接一定没…

2023年蓝桥杯省赛——买二赠一

目录 题目链接&#xff1a;1.买二赠一 - 蓝桥云课 (lanqiao.cn) 题目描述 输入格式 输出格式 样例输入 样例输出 样例说明 思路 队列贪心 代码实现 总结 题目链接&#xff1a;1.买二赠一 - 蓝桥云课 (lanqiao.cn) 题目描述 某商场有 N 件商品&#xff0c;其中第 i 件…