热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mysql语句查询练习

1、创建students表mysql>createtable

           

 

                                                    

1、创建students表
mysql> create table students (
-> id int(10) auto_increment unique primary key,
-> name varchar(20) not null,
-> sex varchar(4),
-> age int(10),
-> class varchar(20) not null,
-> addr varchar(50)
-> );
创建scores表
mysql> create table scores(
-> id int(10) auto_increment primary key,
-> stu_id int(10) not null,
-> subject varchar(20),
-> grade int(10)
-> );

 

2、while循环批量造数据
delimiter $$;
create procedure best_test (count int)
begin
declare i int;
set i=0;
while i
insert into students (name,sex,age)
values ('保总','男',21);
set i=i+1;
end while;
end
$$;

call best_test (500);
3、插入表一数据
INSERT INTO students(id, name, sex, age, class, addr)
VALUES ('801', '刘海洋', '男', '21', '乔巴', '北京市海淀区');
INSERT INTO students(name, sex, age, class, addr)
VALUES ('周飞', '男', '18', '乔巴', '北京市昌平区'),
('味全', '男', '26', '路飞', '湖南省永州市'),
('孙洋', '女', '21', '乔巴', '辽宁省阜新市'),
('李佳', '女', '22', '超人', '福建省厦门市'),
('保总', '女', '30', '乔巴', '湖南省衡阳市');
INSERT INTO students(id, name, sex, age, class, addr) VALUES('1001', '徐振永', '男', '21', '索隆', '辽宁省阜新市');
INSERT INTO students(name, sex, age, class, addr)
values(李卫强', '男', '18', '索隆', '福建省厦门市'),
('狄枫', '男', '26', '蜘蛛侠', '湖南省衡阳市'),
('女屌丝', '女', '21', '蜘蛛侠', '北京市海淀区'),
('郁燕', '女', '22', '索隆', '北京市昌平区'),
('裴颖菲', '女', '30', '索隆', '辽宁省阜新市'),
('1007', '戴小龙', '男', '50', '索隆', '福建省厦门市');

| id | name | sex | age | class | addr |
+------+-----------+------+------+-----------+--------------------+
| 801 | 刘海洋 | 男 | 21 | 乔巴 | 北京市海淀区 |
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 803 | 味全 | 男 | 26 | 路飞 | 湖南省永州市 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 805 | 李佳 | 女 | 22 | 超人 | 福建省厦门市 |
| 806 | 保总 | 女 | 30 | 乔巴 | 湖南省衡阳市 |
| 1001 | 徐振永 | 男 | 21 | 索隆 | 辽宁省阜新市 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
| 1003 | 狄枫 | 男 | 26 | 蜘蛛侠 | 湖南省衡阳市 |
| 1004 | 女屌丝 | 女 | 21 | 蜘蛛侠 | 北京市海淀区 |
| 1005 | 郁燕 | 女 | 22 | 索隆 | 北京市昌平区 |
| 1006 | 裴颖菲 | 女 | 30 | 索隆 | 辽宁省阜新市 |
| 1007 | 戴小龙 | 男 | 50 | 索隆 | 福建省厦门市 |
+------+-----------+------+------+-----------+-------------------
插入表二数据
insert into scores (stu_id,subject,grade) values
-> (801,'计算机',98),
-> (801,'英语',80),
-> (802,'计算机',65),
-> (802,'中文',88),
-> (803,'中文',95),
-> (804,'计算机',70),
-> (804,'英语',92),
-> (805,'英语',94),
-> (806,'计算机',),
-> (806'英语'45),
-> (1001,'计算机',98)
-> (1002,'中文',88),
-> (1003,'中文',95),
-> (1002,'计算机'65),
-> (1004,'计算机',70),
-> (1004,'英语',70),
-> (1005,'英语',94),
-> (1006,'计算机',57),
-> (1006,'英语',45),
-> (1007,'英语',80)
-> ;
| id | stu_id | subject | grade |
+----+--------+-----------+-------+
| 1 | 801 | 英语 | 80 |
| 2 | 801 | 计算机 | 98 |
| 3 | 802 | 计算机 | 65 |
| 4 | 802 | 中文 | 88 |
| 5 | 803 | 中文 | 95 |
| 6 | 804 | 计算机 | 70 |
| 7 | 804 | 英语 | 92 |
| 8 | 805 | 英语 | 94 |
| 9 | 806 | 计算机 | 57 |
| 10 | 806 | 英语 | 45 |
| 11 | 1001 | 计算机 | 98 |
| 12 | 1002 | 中文 | 88 |
| 13 | 1003 | 中文 | 95 |
| 14 | 1002 | 计算机 | 65 |
| 15 | 1004 | 计算机 | 70 |
| 16 | 1004 | 英语 | 70 |
| 17 | 1005 | 英语 | 94 |
| 18 | 1006 | 计算机 | 57 |
| 19 | 1006 | 英语 | 45 |
| 20 | 1007 | 英语 | 80 |
4、查询表students所有内容
select * from students;
+------+-----------+------+------+-----------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+-----------+--------------------+
| 801 | 刘海洋 | 男 | 21 | 乔巴 | 北京市海淀区 |
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 803 | 味全 | 男 | 26 | 路飞 | 湖南省永州市 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 805 | 李佳 | 女 | 22 | 超人 | 福建省厦门市 |
| 806 | 保总 | 女 | 30 | 乔巴 | 湖南省衡阳市 |
| 1001 | 徐振永 | 男 | 21 | 索隆 | 辽宁省阜新市 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
| 1003 | 狄枫 | 男 | 26 | 蜘蛛侠 | 湖南省衡阳市 |
| 1004 | 女屌丝 | 女 | 21 | 蜘蛛侠 | 北京市海淀区 |
| 1005 | 郁燕 | 女 | 22 | 索隆 | 北京市昌平区 |
| 1006 | 裴颖菲 | 女 | 30 | 索隆 | 辽宁省阜新市 |
| 1007 | 戴小龙 | 男 | 50 | 索隆 | 福建省厦门市 |
+------+-----------+------+------+-----------+--------------------
5、查询表students2~4条信息
select * from students limit 1,3;
+-----+--------+------+------+--------+--------------------+
| id | name | sex | age | class | addr |
+-----+--------+------+------+--------+--------------------+
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 803 | 味全 | 男 | 26 | 路飞 | 湖南省永州市 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
+-----+--------+------+------+--------+--------------------+
6、查询表students所有学员的id、name、class
select id '学号', name '姓名', class '班级' from students;
+--------+-----------+-----------+
| 学号 | 姓名 | 班级 |
+--------+-----------+-----------+
| 801 | 刘海洋 | 乔巴 |
| 802 | 周飞 | 乔巴 |
| 803 | 味全 | 路飞 |
| 804 | 孙洋 | 乔巴 |
| 805 | 李佳 | 超人 |
| 806 | 保总 | 乔巴 |
| 1001 | 徐振永 | 索隆 |
| 1002 | 李卫强 | 索隆 |
| 1003 | 狄枫 | 蜘蛛侠 |
| 1004 | 女屌丝 | 蜘蛛侠 |
| 1005 | 郁燕 | 索隆 |
| 1006 | 裴颖菲 | 索隆 |
| 1007 | 戴小龙 | 索隆 |
+--------+-----------+-----------+
7、选出表students中乔巴和索隆班的学员信息
select * from students where class='乔巴' union select * from students where class='索隆';
select * from students where class='乔巴' or class='索隆';#更优
+------+-----------+------+------+--------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+--------+--------------------+
| 801 | 刘海洋 | 男 | 21 | 乔巴 | 北京市海淀区 |
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 806 | 保总 | 女 | 30 | 乔巴 | 湖南省衡阳市 |
| 1001 | 徐振永 | 男 | 21 | 索隆 | 辽宁省阜新市 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
| 1005 | 郁燕 | 女 | 22 | 索隆 | 北京市昌平区 |
| 1006 | 裴颖菲 | 女 | 30 | 索隆 | 辽宁省阜新市 |
| 1007 | 戴小龙 | 男 | 50 | 索隆 | 福建省厦门市 |
+------+-----------+------+------+--------+--------------------+
8、表students中18~25的学员信息
select * from students where age between 18 and 25;
+------+-----------+------+------+-----------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+-----------+--------------------+
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
| 801 | 刘海洋 | 男 | 21 | 乔巴 | 北京市海淀区 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 1001 | 徐振永 | 男 | 21 | 索隆 | 辽宁省阜新市 |
| 1004 | 女屌丝 | 女 | 21 | 蜘蛛侠 | 北京市海淀区 |
| 805 | 李佳 | 女 | 22 | 超人 | 福建省厦门市 |
| 1005 | 郁燕 | 女 | 22 | 索隆 | 北京市昌平区 |
+------+-----------+------+------+-----------+-------------------
9、表students中每班人数
select class '班级',count(*) '人数' from students group by class;
+-----------+--------+
| 班级 | 人数 |
+-----------+--------+
| 乔巴 | 4 |
| 索隆 | 5 |
| 超人 | 1 |
| 路飞 | 1 |
| 蜘蛛侠 | 2 |
+-----------+--------+
10、表score中每科最高分
select subject,max(grade) '最高分' from scores group by subject;
+-----------+-----------+
| subject | 最高分 |
+-----------+-----------+
| 中文 | 95 |
| 计算机 | 98 |
| 英语 | 94 |
+-----------+-----------+
11、查询女屌丝的grade和subject
select subject,grade from scores where stu_id=(select id from students where name='女屌丝');
+-----------+-------+
| subject | grade |
+-----------+-------+
| 计算机 | 70 |
| 英语 | 70 |
12、查询两表所有数据的四种连接方式
=连接
select * from students a,scores b where a.id=b.stu_id;
左连接
SELECT * from students a LEFT JOIN scores b on a.id=b.stu_id;
右连接
SELECT * from students a RIGHT JOIN scores b on a.id=b.stu_id;
内连接
SELECT * from students a INNER JOIN scores b on a.id=b.stu_id;
13、每个学员的总成绩
select stu_id '学号',sum(grade)'总成绩' from scores where stu_id=any(select id from students) group by stu_id;
select stu_id '学号',sum(grade)'总成绩' from scores group by stu_id; #这样果然也行
+--------+-----------+
| 学号 | 总成绩 |
+--------+-----------+
| 801 | 178 |
| 802 | 153 |
| 803 | 95 |
| 804 | 162 |
| 805 | 94 |
| 806 | 102 |
| 1001 | 98 |
| 1002 | 153 |
| 1003 | 95 |
| 1004 | 140 |
| 1005 | 94 |
| 1006 | 102 |
| 1007 | 80 |
14、表socres中每科平均成绩
select AVG(grade) '平均成绩' from scores where subject='计算机' union select AVG(grade) '平均成绩' from scores where subject='英语' union select AVG(grade) '平均成绩' from scores where subject='中文';
select subject,avg(grade) from scores group by subject; #真的好省事
+-----------+------------+
| subject | avg(grade) |
+-----------+------------+
| 中文 | 91.5000 |
| 计算机 | 72.5000 |
| 英语 | 75.0000 |
+-----------+------------+
15、计算机成绩低于95的学员信息
select * from students where id=any(select stu_id from scores where grade <95 and subject='计算机');
+------+-----------+------+------+-----------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+-----------+--------------------+
| 802 | 周飞 | 男 | 18 | 乔巴 | 北京市昌平区 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 806 | 保总 | 女 | 30 | 乔巴 | 湖南省衡阳市 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
| 1004 | 女屌丝 | 女 | 21 | 蜘蛛侠 | 北京市海淀区 |
| 1006 | 裴颖菲 | 女 | 30 | 索隆 | 辽宁省阜新市 |
16、同时参加英语和计算机考试的学员信息
select a.* from students a,scores b,scores c
-> where
-> a.id=b.stu_id
-> and b.subject='英语'
-> and a.id=c.stu_id
-> and c.subject='计算机'
-> ;
+------+-----------+------+------+-----------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+-----------+--------------------+
| 801 | 刘海洋 | 男 | 21 | 乔巴 | 北京市海淀区 |
| 804 | 孙洋 | 女 | 21 | 乔巴 | 辽宁省阜新市 |
| 806 | 保总 | 女 | 30 | 乔巴 | 湖南省衡阳市 |
| 1004 | 女屌丝 | 女 | 21 | 蜘蛛侠 | 北京市海淀区 |
| 1006 | 裴颖菲 | 女 | 30 | 索隆 | 辽宁省阜新市 |
17、计算机考试成绩从高到低排列
select grade '计算机成绩' from scores where subject='计算机' order by grade desc;
+-----------------+
| 计算机成绩 |
+-----------------+
| 98 |
| 98 |
| 70 |
| 70 |
| 65 |
| 65 |
| 57 |
| 57 |
+-----------------+
18、表students和scores查询出的学号合并
select id from students union select stu_id from scores;
+------+
| id |
+------+
| 801 |
| 802 |
| 803 |
| 804 |
| 805 |
| 806 |
| 1001 |
| 1002 |
| 1003 |
| 1004 |
| 1005 |
| 1006 |
| 1007 |
+------+
19、索隆班李姓男同学成绩和信息
select * from students where name like '李%' and sex='男' and class='索隆';
+------+-----------+------+------+--------+--------------------+
| id | name | sex | age | class | addr |
+------+-----------+------+------+--------+--------------------+
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 |
+------+-----------+------+------+--------+--------------------+
select grade from scores where stu_id=(select id from students where name like '李%' and sex='男' and class='索隆');
+-------+
| grade |
+-------+
| 88 |
| 65 |
+-------+
select a.*,b.grade from (select * from students where name like '李%' and sex='男' and class='索隆') a,scores b where a.id=b.stu_id; #果然可以
+------+-----------+------+------+--------+--------------------+-------+
| id | name | sex | age | class | addr | grade |
+------+-----------+------+------+--------+--------------------+-------+
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 | 88 |
| 1002 | 李卫强 | 男 | 18 | 索隆 | 福建省厦门市 | 65 |
+------+-----------+------+------+--------+--------------------+-------+
20、来自湖南的学员姓名、班级、年龄、课程、成绩
select name '姓名', age '年龄', class '班级' from students where addr like '湖南%';
+--------+--------+-----------+
| 姓名 | 年龄 | 班级 |
+--------+--------+-----------+
| 味全 | 26 | 路飞 |
| 保总 | 30 | 乔巴 |
| 狄枫 | 26 | 蜘蛛侠 |
+--------+--------+-----------+
select stu_id '学号', grade '成绩', subject '科目' from scores where stu_id=any(select id from students where addr like '湖南%');
+--------+--------+-----------+
| 学号 | 成绩 | 科目 |
+--------+--------+-----------+
| 803 | 95 | 中文 |
| 806 | 57 | 计算机 |
| 806 | 45 | 英语 |
| 1003 | 95 | 中文 |
+--------+--------+-----------+
select a.*,b.grade '成绩',b.subject '科目' from (select id,name '姓名', age '年龄', class '班级' from students where addr like '湖南%') a,scores b where a.id=b.stu_id;
+------+--------+--------+-----------+--------+-----------+
| id | 姓名 | 年龄 | 班级 | 成绩 | 科目 |
+------+--------+--------+-----------+--------+-----------+
| 803 | 天才 | 26 | 路飞 | 95 | 中文 |
| 806 | 保总 | 30 | 乔巴 | 57 | 计算机 |
| 806 | 保总 | 30 | 乔巴 | 45 | 英语 |
| 1003 | 天才 | 26 | 蜘蛛侠 | 95 | 中文 |
21、总成绩小于100的学员姓名改成天才
select stu_id '学号', sum(grade)'总成绩' from scores group by stu_id ;
+--------+-----------+
| 学号 | 总成绩 |
+--------+-----------+
| 801 | 178 |
| 802 | 153 |
| 803 | 95 |
| 804 | 162 |
| 805 | 94 |
| 806 | 102 |
| 1001 | 98 |
| 1002 | 153 |
| 1003 | 95 |
| 1004 | 140 |
| 1005 | 94 |
| 1006 | 102 |
| 1007 | 80 |
+--------+-----------+
update students set name='天才' where id in (803,805,1001,1003,1005,1007);
22、只学过一门课程的学员信息
select count(*),stu_id from scores group by stu_id ;
+----------+--------+
| count(*) | stu_id |
+----------+--------+
| 2 | 801 |
| 2 | 802 |
| 1 | 803 |
| 2 | 804 |
| 1 | 805 |
| 2 | 806 |
| 1 | 1001 |
| 2 | 1002 |
| 1 | 1003 |
| 2 | 1004 |
| 1 | 1005 |
| 2 | 1006 |
| 1 | 1007 |
select count(*),stu_id from scores group by stu_id having count(*)=1;
+----------+--------+
| count(*) | stu_id |
+----------+--------+
| 1 | 803 |
| 1 | 805 |
| 1 | 1001 |
| 1 | 1003 |
| 1 | 1005 |
| 1 | 1007 |
+----------+-------
select * from students a right join (select count(*),stu_id from scores group by stu_id having count(*)=1) b on a.id=b.stu_id ; #=连接也行
+------+--------+------+------+-----------+--------------------+----------+--------+
| id | name | sex | age | class | addr | count(*) | stu_id |
+------+--------+------+------+-----------+--------------------+----------+--------+
| 803 | 天才 | 男 | 26 | 路飞 | 湖南省永州市 | 1 | 803 |
| 805 | 天才 | 女 | 22 | 超人 | 福建省厦门市 | 1 | 805 |
| 1001 | 天才 | 男 | 21 | 索隆 | 辽宁省阜新市 | 1 | 1001 |
| 1003 | 天才 | 男 | 26 | 蜘蛛侠 | 湖南省衡阳市 | 1 | 1003 |
| 1005 | 天才 | 女 | 22 | 索隆 | 北京市昌平区 | 1 | 1005 |
| 1007 | 天才 | 男 | 50 | 索隆 | 福建省厦门市 | 1 | 1007 |

23、年龄一样的学员人数
select count(*),age from students group by age;
+----------+------+
| count(*) | age |
+----------+------+
| 2 | 18 |
| 4 | 21 |
| 2 | 22 |
| 2 | 26 |
| 2 | 30 |
| 1 | 50 |
+----------+------+
select count(*),age from students group by age having count(*) >1;
+----------+------+
| count(*) | age |
+----------+------+
| 2 | 18 |
| 4 | 21 |
| 2 | 22 |
| 2 | 26 |
| 2 | 30 |
+----------+------+
24、每门课程低于平均分的学生姓名、课程名称、分数
#select a.name,b.subject,b.grade from students a,scores b where a.id=b.stu_id;
#select subject,avg(grade) GPA from scores group by subject;

select st.*,avg.GPA from (select a.name,b.subject,b.grade from students a,scores b where a.id=b.stu_id) st,(select subject,avg(grade) GPA from scores group by subject) avg where st.subject=avg.subject and st.grade
| name | subject | grade | GPA |
+-----------+-----------+-------+---------+
| 周飞 | 计算机 | 65 | 72.5000 |
| 周飞 | 中文 | 88 | 91.5000 |
| 孙洋 | 计算机 | 70 | 72.5000 |
| 保总 | 计算机 | 57 | 72.5000 |
| 保总 | 英语 | 45 | 75.0000 |
| 李卫强 | 中文 | 88 | 91.5000 |
| 李卫强 | 计算机 | 65 | 72.5000 |
| 女屌丝 | 计算机 | 70 | 72.5000 |
| 女屌丝 | 英语 | 70 | 75.0000 |
| 裴颖菲 | 计算机 | 57 | 72.5000 |
| 裴颖菲 | 英语 | 45 | 75.0000 |
25、每个人成绩最高的课程名称及分数
select a.name,b.subject,b.grade from students a,scores b where b.grade in (select max(grade) maximum from scores group by stu_id)and a.id=b.stu_id;+-----------+-----------+-------+
| name | subject | grade |
+-----------+-----------+-------+
| 刘海洋 | 英语 | 80 |
| 刘海洋 | 计算机 | 98 |
| 周飞 | 中文 | 88 |
| 天才 | 中文 | 95 |
| 孙洋 | 计算机 | 70 |
| 孙洋 | 英语 | 92 |
| 天才 | 英语 | 94 |
| 保总 | 计算机 | 57 |
| 天才 | 计算机 | 98 |
| 李卫强 | 中文 | 88 |
| 天才 | 中文 | 95 |
| 女屌丝 | 计算机 | 70 |
| 女屌丝 | 英语 | 70 |
| 天才 | 英语 | 94 |
| 裴颖菲 | 计算机 | 57 |
| 天才 | 英语 | 80 |
SELECT a.id '学号', a.name '姓名', b.subject '课程名称', MAX(b.grade) '最高分' FROM students a,scores b WHERE b.stu_id=a.id GROUP BY b.stu_id;
+--------+-----------+--------------+-----------+
| 学号 | 姓名 | 课程名称 | 最高分 |
+--------+-----------+--------------+-----------+
| 801 | 刘海洋 | 英语 | 98 |
| 802 | 周飞 | 计算机 | 88 |
| 803 | 天才 | 中文 | 95 |
| 804 | 孙洋 | 计算机 | 92 |
| 805 | 天才 | 英语 | 94 |
| 806 | 保总 | 计算机 | 57 |
| 1001 | 天才 | 计算机 | 98 |
| 1002 | 李卫强 | 中文 | 88 |
| 1003 | 天才 | 中文 | 95 |
| 1004 | 女屌丝 | 计算机 | 70 |
| 1005 | 天才 | 英语 | 94 |
| 1006 | 裴颖菲 | 计算机 | 57 |
| 1007 | 天才 | 英语 | 80 |

 


推荐阅读
  • MySQL多表数据库操作方法及子查询详解
    本文详细介绍了MySQL数据库的多表操作方法,包括增删改和单表查询,同时还解释了子查询的概念和用法。文章通过示例和步骤说明了如何进行数据的插入、删除和更新操作,以及如何执行单表查询和使用聚合函数进行统计。对于需要对MySQL数据库进行操作的读者来说,本文是一个非常实用的参考资料。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Python SQLAlchemy库的使用方法详解
    本文详细介绍了Python中使用SQLAlchemy库的方法。首先对SQLAlchemy进行了简介,包括其定义、适用的数据库类型等。然后讨论了SQLAlchemy提供的两种主要使用模式,即SQL表达式语言和ORM。针对不同的需求,给出了选择哪种模式的建议。最后,介绍了连接数据库的方法,包括创建SQLAlchemy引擎和执行SQL语句的接口。 ... [详细]
  • 本文介绍了在MySQL8.0中如何查看性能并解析SQL执行顺序。首先介绍了查询性能工具的开启方法,然后详细解析了SQL执行顺序中的每个步骤,包括from、on、join、where、group by、having、select distinct、union、order by和limit。同时还介绍了虚拟表的概念和生成过程。通过本文的解析,读者可以更好地理解MySQL8.0中的性能查看和SQL执行顺序。 ... [详细]
  • 合并列值-合并为一列问题需求:createtabletab(Aint,Bint,Cint)inserttabselect1,2,3unionallsel ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 本文介绍了在使用Laravel和sqlsrv连接到SQL Server 2016时,如何在插入查询中使用输出子句,并返回所需的值。同时讨论了使用CreatedOn字段返回最近创建的行的解决方法以及使用Eloquent模型创建后,值正确插入数据库但没有返回uniqueidentifier字段的问题。最后给出了一个示例代码。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 超级简单加解密工具的方案和功能
    本文介绍了一个超级简单的加解密工具的方案和功能。该工具可以读取文件头,并根据特定长度进行加密,加密后将加密部分写入源文件。同时,该工具也支持解密操作。加密和解密过程是可逆的。本文还提到了一些相关的功能和使用方法,并给出了Python代码示例。 ... [详细]
author-avatar
歪果仁
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有