当前位置: 首页 > 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;确…...

JavaScript 中的 ES|QL:利用 Apache Arrow 工具

作者&#xff1a;来自 Elastic Jeffrey Rengifo 学习如何将 ES|QL 与 JavaScript 的 Apache Arrow 客户端工具一起使用。 想获得 Elastic 认证吗&#xff1f;了解下一期 Elasticsearch Engineer 培训的时间吧&#xff01; Elasticsearch 拥有众多新功能&#xff0c;助你为自己…...

练习(含atoi的模拟实现,自定义类型等练习)

一、结构体大小的计算及位段 &#xff08;结构体大小计算及位段 详解请看&#xff1a;自定义类型&#xff1a;结构体进阶-CSDN博客&#xff09; 1.在32位系统环境&#xff0c;编译选项为4字节对齐&#xff0c;那么sizeof(A)和sizeof(B)是多少&#xff1f; #pragma pack(4)st…...

线程与协程

1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指&#xff1a;像函数调用/返回一样轻量地完成任务切换。 举例说明&#xff1a; 当你在程序中写一个函数调用&#xff1a; funcA() 然后 funcA 执行完后返回&…...

MMaDA: Multimodal Large Diffusion Language Models

CODE &#xff1a; https://github.com/Gen-Verse/MMaDA Abstract 我们介绍了一种新型的多模态扩散基础模型MMaDA&#xff0c;它被设计用于在文本推理、多模态理解和文本到图像生成等不同领域实现卓越的性能。该方法的特点是三个关键创新:(i) MMaDA采用统一的扩散架构&#xf…...

【RockeMQ】第2节|RocketMQ快速实战以及核⼼概念详解(二)

升级Dledger高可用集群 一、主从架构的不足与Dledger的定位 主从架构缺陷 数据备份依赖Slave节点&#xff0c;但无自动故障转移能力&#xff0c;Master宕机后需人工切换&#xff0c;期间消息可能无法读取。Slave仅存储数据&#xff0c;无法主动升级为Master响应请求&#xff…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...

解析奥地利 XARION激光超声检测系统:无膜光学麦克风 + 无耦合剂的技术协同优势及多元应用

在工业制造领域&#xff0c;无损检测&#xff08;NDT)的精度与效率直接影响产品质量与生产安全。奥地利 XARION开发的激光超声精密检测系统&#xff0c;以非接触式光学麦克风技术为核心&#xff0c;打破传统检测瓶颈&#xff0c;为半导体、航空航天、汽车制造等行业提供了高灵敏…...

实战三:开发网页端界面完成黑白视频转为彩色视频

​一、需求描述 设计一个简单的视频上色应用&#xff0c;用户可以通过网页界面上传黑白视频&#xff0c;系统会自动将其转换为彩色视频。整个过程对用户来说非常简单直观&#xff0c;不需要了解技术细节。 效果图 ​二、实现思路 总体思路&#xff1a; 用户通过Gradio界面上…...

Linux部署私有文件管理系统MinIO

最近需要用到一个文件管理服务&#xff0c;但是又不想花钱&#xff0c;所以就想着自己搭建一个&#xff0c;刚好我们用的一个开源框架已经集成了MinIO&#xff0c;所以就选了这个 我这边对文件服务性能要求不是太高&#xff0c;单机版就可以 安装非常简单&#xff0c;几个命令就…...

[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG

TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码&#xff1a;HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…...