当前位置: 首页 > news >正文

mysql数据库(五)多表查询

多表查询

文章目录

  • 多表查询
  • 一、链表查询
    • 1.1交叉连接
    • 1.2 内连接
    • 1.3 左连接
    • 1.4 右连接
    • 1.5 全连接
    • 1.6 例子
  • 二、子查询
    • 2.1 in与not in
    • 2.2 any/some
    • 2.3 all
    • 2.4 比较运算符
    • 2.5 exists
  • 三、例子

查询中使用的表如下所示


+----+--------+
| id | name   |
+----+--------+
|  1 | IT     |
|  2 | 销售   |
|  3 | 运营   |
|  4 | 安保   |
+----+--------++----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  1 | 张三   |   20 |      1 |
|  2 | 李四   |   25 |      3 |
|  3 | 王五   |   30 |      2 |
|  4 | 赵六   |   31 |      2 |
|  5 | 阿七   |   18 |   NULL |
+----+--------+------+--------+

一、链表查询

链表查询的本质是将多张表拼接在一块形成一张新表,再对新表进行查询。
SELECT 字段 FROM 表1 INNER|LEFT|RIGHT JOIN 表2 ON 表1.字段 = 表2.字段;

1.1交叉连接

#交叉连接不能加任何的匹配条件,生成的结果是两张表的笛卡尔积
select * from employee,department;
+----+--------+------+--------+----+--------+
| id | name   | age  | dep_id | id | name   |
+----+--------+------+--------+----+--------+
|  1 | 张三   |   20 |      1 |  4 | 安保   |
|  1 | 张三   |   20 |      1 |  3 | 运营   |
|  1 | 张三   |   20 |      1 |  2 | 销售   |
|  1 | 张三   |   20 |      1 |  1 | IT     |
|  2 | 李四   |   25 |      3 |  4 | 安保   |
|  2 | 李四   |   25 |      3 |  3 | 运营   |
|  2 | 李四   |   25 |      3 |  2 | 销售   |
|  2 | 李四   |   25 |      3 |  1 | IT     |
|  3 | 王五   |   30 |      2 |  4 | 安保   |
|  3 | 王五   |   30 |      2 |  3 | 运营   |
|  3 | 王五   |   30 |      2 |  2 | 销售   |
|  3 | 王五   |   30 |      2 |  1 | IT     |
|  4 | 赵六   |   31 |      2 |  4 | 安保   |
|  4 | 赵六   |   31 |      2 |  3 | 运营   |
|  4 | 赵六   |   31 |      2 |  2 | 销售   |
|  4 | 赵六   |   31 |      2 |  1 | IT     |
|  5 | 阿七   |   18 |   NULL |  4 | 安保   |
|  5 | 阿七   |   18 |   NULL |  3 | 运营   |
|  5 | 阿七   |   18 |   NULL |  2 | 销售   |
|  5 | 阿七   |   18 |   NULL |  1 | IT     |
+----+--------+------+--------+----+--------+

1.2 内连接

#内连接是根据匹配条件将两张表的公共部分连接起来
select * from employee inner join department on employee.dep_id=department.id;
+----+--------+------+--------+----+--------+
| id | name   | age  | dep_id | id | name   |
+----+--------+------+--------+----+--------+
|  1 | 张三   |   20 |      1 |  1 | IT     |
|  2 | 李四   |   25 |      3 |  3 | 运营   |
|  3 | 王五   |   30 |      2 |  2 | 销售   |
|  4 | 赵六   |   31 |      2 |  2 | 销售   |
+----+--------+------+--------+----+--------+

1.3 左连接

#左连接是以左表为基准将右表符合匹配条件的信息拼接到左表,左表中匹配不上的记录会被保留
select * from employee left join department on employee.dep_id=department.id;
+----+--------+------+--------+------+--------+
| id | name   | age  | dep_id | id   | name   |
+----+--------+------+--------+------+--------+
|  1 | 张三   |   20 |      1 |    1 | IT     |
|  2 | 李四   |   25 |      3 |    3 | 运营   |
|  3 | 王五   |   30 |      2 |    2 | 销售   |
|  4 | 赵六   |   31 |      2 |    2 | 销售   |
|  5 | 阿七   |   18 |   NULL | NULL | NULL   |
+----+--------+------+--------+------+--------+

1.4 右连接

#右连接是以右表为基准将左表符合匹配条件的信息拼接到右表,右表中匹配不上的记录会被保留
select * from employee right join department on employee.dep_id=department.id;
+------+--------+------+--------+----+--------+
| id   | name   | age  | dep_id | id | name   |
+------+--------+------+--------+----+--------+
|    1 | 张三   |   20 |      1 |  1 | IT     |
|    4 | 赵六   |   31 |      2 |  2 | 销售   |
|    3 | 王五   |   30 |      2 |  2 | 销售   |
|    2 | 李四   |   25 |      3 |  3 | 运营   |
| NULL | NULL   | NULL |   NULL |  4 | 安保   |
+------+--------+------+--------+----+--------+

1.5 全连接

#全连接是将两张表根据匹配条件拼接记录,同时保留两张表中匹配不到的记录。
#由于mysql不支持full join操作,所以使用union来模拟全连接操作
#union的作用是将两张表合并,这个关键字会自动完成去重、排序等操作。
select * from employee left join department on employee.dep_id=department.id 
union 
select * from employee right join department on employee.dep_id=department.id;
+------+--------+------+--------+------+--------+
| id   | name   | age  | dep_id | id   | name   |
+------+--------+------+--------+------+--------+
|    1 | 张三   |   20 |      1 |    1 | IT     |
|    2 | 李四   |   25 |      3 |    3 | 运营   |
|    3 | 王五   |   30 |      2 |    2 | 销售   |
|    4 | 赵六   |   31 |      2 |    2 | 销售   |
|    5 | 阿七   |   18 |   NULL | NULL | NULL   |
| NULL | NULL   | NULL |   NULL |    4 | 安保   |
+------+--------+------+--------+------+--------+

1.6 例子

#现在需要针对上面的表格查询出销售部门的员工信息并按年龄升序排序
#在链表操作中,如果字段只有某一张表含有,可以直接写字段不用写为表.字段的形式
#如下方order by后的age只有employee有,可以直接写age,不用写为employee.age
select * from employee inner join department on employee.dep_id=department.id 
where department.name='销售' order by age;
+----+--------+------+--------+----+--------+
| id | name   | age  | dep_id | id | name   |
+----+--------+------+--------+----+--------+
|  3 | 王五   |   30 |      2 |  2 | 销售   |
|  4 | 赵六   |   31 |      2 |  2 | 销售   |
+----+--------+------+--------+----+--------+#查询IT部门的员工姓名、年龄信息
select employee.id,employee.name,age from employee inner join department 
on employee.dep_id=department.id where department.name='IT';
+----+--------+------+
| id | name   | age  |
+----+--------+------+
|  1 | 张三   |   20 |
+----+--------+------+

二、子查询

子查询是指先查询一张表的信息,将查询到的信息作为另一张表的查询条件继续查询,以此重复直到查询出结果。

2.1 in与not in

#查询销售部门的员工信息
#下面的查询语句中先查询department表销售部门的id,再查询dep_id与id一致的员工信息
#需要注意的是如果select后只有一个字段,查询结果返回的是一个集合可以使用in,如果select后是多个字段查询结果是一张表无法使用in
select * from employee where dep_id in (select id from department where name='销售');
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  3 | 王五   |   30 |      2 |
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+#需要注意not in无法处理null
#例如寻找没有员工的部门,由于括号中的查询结果返回集合含有null,not in无法处理以此结果为空
select * from department where id not in (select dep_id from employee);
Empty set (0.00 sec)#对上述的问题可以这样改进
select * from department where id not in (select dep_id from employee where dep_id is not null);
+----+--------+
| id | name   |
+----+--------+
|  4 | 安保   |
+----+--------+

2.2 any/some

any表示某一个的意思,它与in的区别是any后面必须是查询的结果,不能直接是集合。
mysql中some的用法和any完全一致。
例如select * from t1 where id in (1,2);可以,但是select * from t1 where id=any (1,2);则不行。

#查询每个部门年龄最大的员工
#age=any和age in其实是等价的
#而>any的意思是比集合中某一个大,翻译一下就是比集合中最小的那个大就行,同样的<any的意思是比集合中某一个小,翻译一下就是比集合中最大的那个小就行
select * from employee where age=
any(select max(age) from employee where dep_id is not null group by dep_id);
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  1 | 张三   |   20 |      1 |
|  2 | 李四   |   25 |      3 |
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+

2.3 all

all表示所有的意思,all和any一样后面不能直接加集合,只能比较查询结果

#查询年龄比所有部门平均年龄高的员工信息
select * from employee where age>
all(select avg(age) from employee where dep_id is not null group by dep_id);
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+#查询年龄比某一个部门平均年龄高的员工信息
select * from employee where age>
any(select avg(age) from employee where dep_id is not null group by dep_id);
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  2 | 李四   |   25 |      3 |
|  3 | 王五   |   30 |      2 |
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+

2.4 比较运算符

比较运算符有=、!=、>、>=、<、<=、<>

#查询年龄比所有员工平均年龄大的员工信息
select * from employee where age>(select avg(age) from employee);
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  2 | 李四   |   25 |      3 |
|  3 | 王五   |   30 |      2 |
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+

2.5 exists

exists关字键字表示存在。使用exists时,内层查询语句不返回查询的记录,而是返回一个真假值。当内存查询语句查询到记录时返回True,外层查询语句返回结果,反之则返回False,外层查询语句不返回结果。

exists的执行过程:

  • 依次执外部查询
  • 然后为外部查询返回的每一行分别执行一次子查询
  • 子查询如果返回记录,则exists条件成立,外部查询语句返回结果

下面拿exists和in的执行进行比较,in的子查询会先产生结果集,然后外部查询再去结果集里去找符合要求的字段返回结果。由此可以看出exists的查询效率是远不如in的。

#由于department中没有id=5的记录,使用exists返回False,以此外层的查询语句不执行
select * from employee where exists(select * from department where id=5);
Empty set (0.00 sec)#查询有部门的员工的员工信息
select * from employee where 
exists(select * from department where employee.dep_id=department.id);
+----+--------+------+--------+
| id | name   | age  | dep_id |
+----+--------+------+--------+
|  1 | 张三   |   20 |      1 |
|  2 | 李四   |   25 |      3 |
|  3 | 王五   |   30 |      2 |
|  4 | 赵六   |   31 |      2 |
+----+--------+------+--------+

三、例子

使用到的表生成代码如下:

/*数据导入:Navicat Premium Data TransferSource Server         : localhostSource Server Type    : MySQLSource Server Version : 50624Source Host           : localhostSource Database       : sqlexamTarget Server Type    : MySQLTarget Server Version : 50624File Encoding         : utf-8Date: 10/21/2016 06:46:46 AM
*/SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
--  Table structure for `class`
-- ----------------------------
DROP TABLE IF EXISTS `class`;
CREATE TABLE `class` (`cid` int(11) NOT NULL AUTO_INCREMENT,`caption` varchar(32) NOT NULL,PRIMARY KEY (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;-- ----------------------------
--  Records of `class`
-- ----------------------------
BEGIN;
INSERT INTO `class` VALUES ('1', '三年二班'), ('2', '三年三班'), ('3', '一年二班'), ('4', '二年九班');
COMMIT;-- ----------------------------
--  Table structure for `course`
-- ----------------------------
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (`cid` int(11) NOT NULL AUTO_INCREMENT,`cname` varchar(32) NOT NULL,`teacher_id` int(11) NOT NULL,PRIMARY KEY (`cid`),KEY `fk_course_teacher` (`teacher_id`),CONSTRAINT `fk_course_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`tid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;-- ----------------------------
--  Records of `course`
-- ----------------------------
BEGIN;
INSERT INTO `course` VALUES ('1', '生物', '1'), ('2', '物理', '2'), ('3', '体育', '3'), ('4', '美术', '2');
COMMIT;-- ----------------------------
--  Table structure for `score`
-- ----------------------------
DROP TABLE IF EXISTS `score`;
CREATE TABLE `score` (`sid` int(11) NOT NULL AUTO_INCREMENT,`student_id` int(11) NOT NULL,`course_id` int(11) NOT NULL,`num` int(11) NOT NULL,PRIMARY KEY (`sid`),KEY `fk_score_student` (`student_id`),KEY `fk_score_course` (`course_id`),CONSTRAINT `fk_score_course` FOREIGN KEY (`course_id`) REFERENCES `course` (`cid`),CONSTRAINT `fk_score_student` FOREIGN KEY (`student_id`) REFERENCES `student` (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8;-- ----------------------------
--  Records of `score`
-- ----------------------------
BEGIN;
INSERT INTO `score` VALUES ('1', '1', '1', '10'), ('2', '1', '2', '9'), ('5', '1', '4', '66'), ('6', '2', '1', '8'), ('8', '2', '3', '68'), ('9', '2', '4', '99'), ('10', '3', '1', '77'), ('11', '3', '2', '66'), ('12', '3', '3', '87'), ('13', '3', '4', '99'), ('14', '4', '1', '79'), ('15', '4', '2', '11'), ('16', '4', '3', '67'), ('17', '4', '4', '100'), ('18', '5', '1', '79'), ('19', '5', '2', '11'), ('20', '5', '3', '67'), ('21', '5', '4', '100'), ('22', '6', '1', '9'), ('23', '6', '2', '100'), ('24', '6', '3', '67'), ('25', '6', '4', '100'), ('26', '7', '1', '9'), ('27', '7', '2', '100'), ('28', '7', '3', '67'), ('29', '7', '4', '88'), ('30', '8', '1', '9'), ('31', '8', '2', '100'), ('32', '8', '3', '67'), ('33', '8', '4', '88'), ('34', '9', '1', '91'), ('35', '9', '2', '88'), ('36', '9', '3', '67'), ('37', '9', '4', '22'), ('38', '10', '1', '90'), ('39', '10', '2', '77'), ('40', '10', '3', '43'), ('41', '10', '4', '87'), ('42', '11', '1', '90'), ('43', '11', '2', '77'), ('44', '11', '3', '43'), ('45', '11', '4', '87'), ('46', '12', '1', '90'), ('47', '12', '2', '77'), ('48', '12', '3', '43'), ('49', '12', '4', '87'), ('52', '13', '3', '87');
COMMIT;-- ----------------------------
--  Table structure for `student`
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (`sid` int(11) NOT NULL AUTO_INCREMENT,`gender` char(1) NOT NULL,`class_id` int(11) NOT NULL,`sname` varchar(32) NOT NULL,PRIMARY KEY (`sid`),KEY `fk_class` (`class_id`),CONSTRAINT `fk_class` FOREIGN KEY (`class_id`) REFERENCES `class` (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;-- ----------------------------
--  Records of `student`
-- ----------------------------
BEGIN;
INSERT INTO `student` VALUES ('1', '男', '1', '理解'), ('2', '女', '1', '钢蛋'), ('3', '男', '1', '张三'), ('4', '男', '1', '张一'), ('5', '女', '1', '张二'), ('6', '男', '1', '张四'), ('7', '女', '2', '铁锤'), ('8', '男', '2', '李三'), ('9', '男', '2', '李一'), ('10', '女', '2', '李二'), ('11', '男', '2', '李四'), ('12', '女', '3', '如花'), ('13', '男', '3', '刘三'), ('14', '男', '3', '刘一'), ('15', '女', '3', '刘二'), ('16', '男', '3', '刘四');
COMMIT;-- ----------------------------
--  Table structure for `teacher`
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (`tid` int(11) NOT NULL AUTO_INCREMENT,`tname` varchar(32) NOT NULL,PRIMARY KEY (`tid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;-- ----------------------------
--  Records of `teacher`
-- ----------------------------
BEGIN;
INSERT INTO `teacher` VALUES ('1', '张磊老师'), ('2', '李平老师'), ('3', '刘海燕老师'), ('4', '朱云海老师'), ('5', '李杰老师');
COMMIT;SET FOREIGN_KEY_CHECKS = 1;

例子中表的结构如下所示:
在这里插入图片描述
现在需要针对表中的数据进行如下的操作:

#查询物理课程比生物课程高的学生的学号
select b.student_id from 
(select student_id,num as biology from score where course_id in
(select cid from course where cname='生物')) as b 
inner join 
(select student_id,num as physcis from score where course_id in
(select cid from course where cname='物理')) as p 
on b.student_id=p.student_id 
where b.biology<p.physcis;
+------------+
| student_id |
+------------+
|          6 |
|          7 |
|          8 |
+------------+#查询挂科超过两门(包括两门)的学生姓名和班级
select sname,caption from class inner join student on cid=sid where sid in
(select student_id from score where num<60 group by student_id having count(num)>=2);
+--------+--------------+
| sname  | caption      |
+--------+--------------+
| 理解   | 三年二班     |
+--------+--------------+#查询所有选修了学号为1的同学选修过的一门或者多门课程的同学学号和姓名;
select distinct sname,student.sid from student inner join score on student_id=student.sid 
where course_id in(select course_id from score where student_id=1) and student_id!=1;
+--------+-----+
| sname  | sid |
+--------+-----+
| 钢蛋   |   2 |
| 张三   |   3 |
| 张一   |   4 |
| 张二   |   5 |
| 张四   |   6 |
| 铁锤   |   7 |
| 李三   |   8 |
| 李一   |   9 |
| 李二   |  10 |
| 李四   |  11 |
| 如花   |  12 |
+--------+-----+#查询在所有选修了李平老师课程的学生中,这些课程(李平老师的课程,不是所有课程)平均成绩最高的学生姓名
select sname,avg(num) from student inner join score on student.sid=student_id where course_id 
in((select cid from course inner join teacher on tid=teacher_id where tname='李平老师')) 
group by sname order by avg(num) desc limit 1;
+--------+----------+
| sname  | avg(num) |
+--------+----------+
| 张四   | 100.0000 |
+--------+----------+#查询不同课程但成绩相同的学号,课程号,成绩
select s1.student_id,s1.course_id,s1.num,s2.student_id,s2.course_id,s2.num 
from score as s1,score as s2 
where s1.num=s2.num and s1.course_id!=s2.course_id;
+------------+-----------+-----+------------+-----------+-----+
| student_id | course_id | num | student_id | course_id | num |
+------------+-----------+-----+------------+-----------+-----+
|          8 |         1 |   9 |          1 |         2 |   9 |
|          7 |         1 |   9 |          1 |         2 |   9 |
|          6 |         1 |   9 |          1 |         2 |   9 |
|          3 |         2 |  66 |          1 |         4 |  66 |
|         12 |         2 |  77 |          3 |         1 |  77 |
|         11 |         2 |  77 |          3 |         1 |  77 |
|         10 |         2 |  77 |          3 |         1 |  77 |
|          1 |         4 |  66 |          3 |         2 |  66 |
|         12 |         4 |  87 |          3 |         3 |  87 |
|         11 |         4 |  87 |          3 |         3 |  87 |
|         10 |         4 |  87 |          3 |         3 |  87 |
|          8 |         2 | 100 |          4 |         4 | 100 |
|          7 |         2 | 100 |          4 |         4 | 100 |
|          6 |         2 | 100 |          4 |         4 | 100 |
|          8 |         2 | 100 |          5 |         4 | 100 |
|          7 |         2 | 100 |          5 |         4 | 100 |
|          6 |         2 | 100 |          5 |         4 | 100 |
|          1 |         2 |   9 |          6 |         1 |   9 |
|          6 |         4 | 100 |          6 |         2 | 100 |
|          5 |         4 | 100 |          6 |         2 | 100 |
|          4 |         4 | 100 |          6 |         2 | 100 |
|          8 |         2 | 100 |          6 |         4 | 100 |
|          7 |         2 | 100 |          6 |         4 | 100 |
|          6 |         2 | 100 |          6 |         4 | 100 |
|          1 |         2 |   9 |          7 |         1 |   9 |
|          6 |         4 | 100 |          7 |         2 | 100 |
|          5 |         4 | 100 |          7 |         2 | 100 |
|          4 |         4 | 100 |          7 |         2 | 100 |
|          9 |         2 |  88 |          7 |         4 |  88 |
|          1 |         2 |   9 |          8 |         1 |   9 |
|          6 |         4 | 100 |          8 |         2 | 100 |
|          5 |         4 | 100 |          8 |         2 | 100 |
|          4 |         4 | 100 |          8 |         2 | 100 |
|          9 |         2 |  88 |          8 |         4 |  88 |
|          8 |         4 |  88 |          9 |         2 |  88 |
|          7 |         4 |  88 |          9 |         2 |  88 |
|          3 |         1 |  77 |         10 |         2 |  77 |
|         13 |         3 |  87 |         10 |         4 |  87 |
|          3 |         3 |  87 |         10 |         4 |  87 |
|          3 |         1 |  77 |         11 |         2 |  77 |
|         13 |         3 |  87 |         11 |         4 |  87 |
|          3 |         3 |  87 |         11 |         4 |  87 |
|          3 |         1 |  77 |         12 |         2 |  77 |
|         13 |         3 |  87 |         12 |         4 |  87 |
|          3 |         3 |  87 |         12 |         4 |  87 |
|         12 |         4 |  87 |         13 |         3 |  87 |
|         11 |         4 |  87 |         13 |         3 |  87 |
|         10 |         4 |  87 |         13 |         3 |  87 |
+------------+-----------+-----+------------+-----------+-----+

相关文章:

mysql数据库(五)多表查询

多表查询 文章目录 多表查询一、链表查询1.1交叉连接1.2 内连接1.3 左连接1.4 右连接1.5 全连接1.6 例子 二、子查询2.1 in与not in2.2 any/some2.3 all2.4 比较运算符2.5 exists 三、例子 查询中使用的表如下所示 ------------ | id | name | ------------ | 1 | IT | …...

【go从零单排】JSON序列化和反序列化

&#x1f308;Don’t worry , just coding! 内耗与overthinking只会削弱你的精力&#xff0c;虚度你的光阴&#xff0c;每天迈出一小步&#xff0c;回头时发现已经走了很远。 &#x1f4d7;概念 在 Go 语言中&#xff0c;处理 JSON 数据主要依赖于 encoding/json 包。这个包提…...

海外携程机票token 1001分析

声明: 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;抓包内容、敏感网址、数据接口等均已做脱敏处理&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01; 有相关问题请第一时间头像私信联系我删…...

【算法】——二分查找合集

阿华代码&#xff0c;不是逆风&#xff0c;就是我疯 你们的点赞收藏是我前进最大的动力&#xff01;&#xff01; 希望本文内容能够帮助到你&#xff01;&#xff01; 目录 零&#xff1a;二分查找工具 1&#xff1a;最基础模版 2&#xff1a;mid落点问题 一&#xff1a;最…...

社会工程骗局席卷金融机构

2024 年北美金融机构收到的社交工程诈骗报告数量比一年前增加了 10 倍。数据显示&#xff0c;诈骗现在占所有数字银行欺诈的 23%。 深度伪造和 GenAI 诈骗的危险日益增加 BioCatch 在其 2024 年北美数字银行欺诈趋势报告中公布了这些发现&#xff0c;该报告还详细说明了报告的…...

前缀和算法习题篇(上)

1.一维前缀和 题目描述&#xff1a; 解法一&#xff1a;暴力解法&#xff1a;模拟 时间复杂度是O(n*q),会超时。 解法二&#xff1a;前缀和解法&#xff1a;快速求出数组中某一个连续区间的和 快速是指O(1),前缀和思想可把时间复杂度可降到O(q)。 算法思路&#xff1a; 先预处…...

C#核心(9)静态类和静态构造函数

前言 我们先前已经了解了静态成员的基本构成&#xff0c;也简单了解了一下静态变量&#xff0c;现在我们就要来看一下静态类和静态构造函数了&#xff0c;这些其实在上一节我已经在例子里有提到过&#xff0c;相信聪明的你甚至已经发现了一些规律。 GPT对c#中静态类和静态构造…...

B2002 Hello,World! C++实现

Hello,World! 题目描述 编写一个能够输出 Hello,World! 的程序。 提示&#xff1a; 使用英文标点符号&#xff1b;Hello,World! 逗号后面没有空格。H 和 W 为大写字母。 输入格式 输出格式 样例 #1 样例输入 #1 无样例输出 #1 Hello,World!#include <bits/stdc.h&…...

前端-同源与跨域

一、同源策略 两个网站协议名、域名、端口号有一个不同就是非同源&#xff0c;就是跨域。跨域问题就是浏览器的同源策略造成的。 同源是指协议名、域名、端口号 必须完全一致&#xff01; http 默认端口号是80&#xff0c;https 默认端口号是443 同源策略的限制 一般来说&…...

MySQL远程连接错误解决:Host is not allowed to connect to this MySQL server

1. 异常错误 通过远程客户端访问MySQL服务器时会遇到“Host is not allowed to connect to this MySQL server”的错误提示。 2. 原因 MySQL服务器当前配置不允许来自特定主机的连接尝试。 3. 解决方法 允许远程主机访问MySQL服务器&#xff0c;按照以下步骤操作&#xff…...

详解C语言字符和字符串的输入与输出

字符和字符串的输入与输出 一、字符的输入与输出1.1 字符的输入使用 getchar()使用 scanf() 1.2 字符的输出使用 putchar()使用 printf() 二、字符串的输入与输出2.1 字符串的输入使用 scanf() 输入字符串使用 fgets() 输入字符串 2.2 字符串的输出使用 printf() 输出字符串使用…...

adworld - stack2

adworld - stack2 题目概述&#xff1a;给一个数组(自己控制数组大小和填入的数据)&#xff0c;并进行(展示, 增加, 修改值, 求平均值, 退出)菜单选项 存在后门函数(system(“/bin/bash”))&#xff0c;但是没找到栈溢出的点 没判断数组的边界造成任意地址修改 但是如何准确…...

Python学习从0到1 day28 Python 高阶技巧 ⑤ 多线程

若事与愿违&#xff0c;请相信&#xff0c;上天自有安排&#xff0c;允许一切如其所是 —— 24.11.12 一、进程、线程 现代操作系统比如Mac OS X&#xff0c;UNIX&#xff0c;Linux&#xff0c;Windows等&#xff0c;都是支持“多任务”的操作系统。 进程 进程&#xff1a;就…...

nuget 管理全局包、缓存和临时文件夹

查看文件夹位置 dotnet nuget locals all --list清空数据 # Clear the 3.x cache (use either command) dotnet nuget locals http-cache --clear nuget locals http-cache -clear# Clear the 2.x cache (NuGet CLI 3.5 and earlier only) nuget locals packages-cache -clea…...

linux物理内存管理:node,zone,page

一、总览 对于物理内存内存&#xff0c;linux对内存的组织逻辑从上到下依次是&#xff1a;node&#xff0c;zone&#xff0c;page&#xff0c;这些page是根据buddy分配算法组织的&#xff0c;看下面两张图&#xff1a; 上面的概念做下简单的介绍&#xff1a; Node&#xff1a…...

uniapp 设置安全区域

<!-- 获取安全区域 --> <script setup lang"ts"> import { computed, ref } from vuelet systemType ref(1) // #ifdef APP-PLUS || H5 || APP-PLUS-NVUE systemType.value 1 const { safeAreaInsets } uni.getSystemInfoSync() console.log(safeAre…...

渐进式JavaScript框架Vue 3 入门

目录 前言1. Vue 3 的基础入门1.1 什么是 Vue.js1.2 局部使用 Vue 2. Vue 3 的基本配置2.1 准备 HTML 页面并引入 Vue 模块2.2 创建 Vue 应用实例 3. Vue 的数据绑定与界面渲染3.1 插值表达式 4. 常用指令详解4.1 v-for 指令&#xff1a;列表渲染4.2 v-bind 指令&#xff1a;绑…...

【真题笔记】21年系统架构设计师案例理论点总结

【真题笔记】21年系统架构设计师案例理论点总结 从机器学习定义的灵活性和学习算法的可扩展性,对解释器+管道过滤器+隐式调用进行对比分析!面向对象方法开发软件,建立对象模型+动态模型+功能模型,三者关联关系!数据架构的设计过程包括:数据定义、数据分布、数据管理,三者…...

PostgreSQL的奥秘:深入探究事务与锁的秘密世界

PostgreSQL事务 1. 概述 在数据库系统中&#xff0c;事务&#xff08;Transaction&#xff09;是执行数据库操作的最小逻辑单位。它确保了一组操作的完整性和一致性。事务可以通过显式的 BEGIN、COMMIT 和 ROLLBACK 语句块来控制&#xff0c;也可以在自动提交模式&#xff08…...

Python进行GRPC和Dubbo协议的高级测试

在微服务架构日益流行的今天&#xff0c;分布式系统的复杂性不断增加。GRPC 和 Dubbo 协议作为当今互联网行业中常见的高性能通信协议&#xff0c;已经成为服务之间交互的核心。然而&#xff0c;随着服务调用层次的不断增加&#xff0c;如何有效地测试这两种协议&#xff0c;确…...

谷歌浏览器插件

项目中有时候会用到插件 sync-cookie-extension1.0.0&#xff1a;开发环境同步测试 cookie 至 localhost&#xff0c;便于本地请求服务携带 cookie 参考地址&#xff1a;https://juejin.cn/post/7139354571712757767 里面有源码下载下来&#xff0c;加在到扩展即可使用FeHelp…...

大话软工笔记—需求分析概述

需求分析&#xff0c;就是要对需求调研收集到的资料信息逐个地进行拆分、研究&#xff0c;从大量的不确定“需求”中确定出哪些需求最终要转换为确定的“功能需求”。 需求分析的作用非常重要&#xff0c;后续设计的依据主要来自于需求分析的成果&#xff0c;包括: 项目的目的…...

数据链路层的主要功能是什么

数据链路层&#xff08;OSI模型第2层&#xff09;的核心功能是在相邻网络节点&#xff08;如交换机、主机&#xff09;间提供可靠的数据帧传输服务&#xff0c;主要职责包括&#xff1a; &#x1f511; 核心功能详解&#xff1a; 帧封装与解封装 封装&#xff1a; 将网络层下发…...

Module Federation 和 Native Federation 的比较

前言 Module Federation 是 Webpack 5 引入的微前端架构方案&#xff0c;允许不同独立构建的应用在运行时动态共享模块。 Native Federation 是 Angular 官方基于 Module Federation 理念实现的专为 Angular 优化的微前端方案。 概念解析 Module Federation (模块联邦) Modul…...

【git】把本地更改提交远程新分支feature_g

创建并切换新分支 git checkout -b feature_g 添加并提交更改 git add . git commit -m “实现图片上传功能” 推送到远程 git push -u origin feature_g...

【HTML-16】深入理解HTML中的块元素与行内元素

HTML元素根据其显示特性可以分为两大类&#xff1a;块元素(Block-level Elements)和行内元素(Inline Elements)。理解这两者的区别对于构建良好的网页布局至关重要。本文将全面解析这两种元素的特性、区别以及实际应用场景。 1. 块元素(Block-level Elements) 1.1 基本特性 …...

用docker来安装部署freeswitch记录

今天刚才测试一个callcenter的项目&#xff0c;所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...

C#中的CLR属性、依赖属性与附加属性

CLR属性的主要特征 封装性&#xff1a; 隐藏字段的实现细节 提供对字段的受控访问 访问控制&#xff1a; 可单独设置get/set访问器的可见性 可创建只读或只写属性 计算属性&#xff1a; 可以在getter中执行计算逻辑 不需要直接对应一个字段 验证逻辑&#xff1a; 可以…...

08. C#入门系列【类的基本概念】:开启编程世界的奇妙冒险

C#入门系列【类的基本概念】&#xff1a;开启编程世界的奇妙冒险 嘿&#xff0c;各位编程小白探险家&#xff01;欢迎来到 C# 的奇幻大陆&#xff01;今天咱们要深入探索这片大陆上至关重要的 “建筑”—— 类&#xff01;别害怕&#xff0c;跟着我&#xff0c;保准让你轻松搞…...

NPOI操作EXCEL文件 ——CAD C# 二次开发

缺点:dll.版本容易加载错误。CAD加载插件时&#xff0c;没有加载所有类库。插件运行过程中用到某个类库&#xff0c;会从CAD的安装目录找&#xff0c;找不到就报错了。 【方案2】让CAD在加载过程中把类库加载到内存 【方案3】是发现缺少了哪个库&#xff0c;就用插件程序加载进…...