SQL
文章平均质量分 89
sql学习
ljm_99
愿自己开开心心找一份适合自己的工作....
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
mysql牛客刷题(SQL大厂面试真题)
mysql牛客刷题(SQL大厂面试真题)系列原创 2022-05-03 11:48:30 · 3313 阅读 · 1 评论 -
mysql牛客刷题(SQL进阶挑战)
牛客网sql进阶挑战题目整理原创 2022-04-11 16:47:25 · 5083 阅读 · 0 评论 -
mysql面试题
对常见mysql的面试题进行总结原创 2022-01-20 11:24:19 · 2113 阅读 · 2 评论 -
mysql牛客刷题(非技术快速入门)
对牛客网常见题进行记录原创 2020-09-25 12:25:58 · 1330 阅读 · 0 评论 -
幻读和串行化
幻读将隔离级别设置为REPEATABLE READ(可被重复读取):SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ;SELECT @@GLOBAL.TRANSACTION_ISOLATION;+--------------------------------+| @@GLOBAL.TRANSACTION_ISOLATION |...原创 2019-12-19 09:29:32 · 733 阅读 · 0 评论 -
脏读
测试 READ UNCOMMITTED(读取未提交)的隔离性;insert into user values(3,'小明',1000);insert into user values(4,'淘宝店',1000);select * from user;+----+-----------+-------+| id | name | money |+----+-----------...原创 2019-12-18 22:06:36 · 141 阅读 · 0 评论 -
事务的隔离性
事务的隔离性分四种(性能从低到高):1、read uncommitted(读取未提交)如有多个事务,那么任意事务都可以看见其他事务未提交的数据2、read commited(读取已提交)只能读取其他事务已经提交的数据3、repeatable read(可被重复读)如果有多个连接都开启了事务,那么事务之间不能共享数据记录,否则只能共享已提交的记录。4、SERIALIZABLE(串行化)...原创 2019-12-18 19:59:44 · 157 阅读 · 0 评论 -
手动开启事务和事务的ACID特征与使用
手动开启事务事务默认提交被开启(@@autocommit=1)后,此时不能使用事务回滚,但我们可手动开启一个事务处理事件,这样就可以发生回滚。使用begin 或者star transaction 手动开启一个事务begin;update user set money=money-100 where name='a';update user set money=money+100 wher...原创 2019-12-18 09:58:48 · 391 阅读 · 0 评论 -
内连接、左外连接、右外连接、全外连接
内连接要查询两张表中有关系的数据,可用内连接将它们连接到一起inner join(join):表示内连接,将两张表连接在一起on:表示执行某个条件select * from person join card on person.cardId=card.id;±-----±-------±-------±-----±----------+| id | name | cardId...原创 2019-12-16 20:46:45 · 217 阅读 · 0 评论 -
连接查询(数据准备)
准备测试数据create database testjoin;create table person(id int,name varchar(20),cardId int);create table card (id int,name varchar(20));insert into card values(1,'饭卡'),(2,'建行卡'),(3,'农行卡'),(4,'工商...原创 2019-12-16 14:48:08 · 169 阅读 · 0 评论 -
按等级查询
建立一个grade 代表学生的成绩表,并插入数据create table grade(low int(3),upp int(3),grade char(1));insert into grade values(90,100,'A');INSERT INTO grade VALUES(80,89,'B');INSERT INTO grade VALUES(70,79,'C');IN...原创 2019-12-16 14:37:26 · 261 阅读 · 0 评论 -
37-42
37.以班级号和年龄从大到小的顺序查询student表中的全部记录select * from student order by class desc,birthday asc;38、查询"男"教师 及其所上的课select * from course where t_no in(select no from teacher where sex='男');39、查询最高分同学的 sc...原创 2019-12-16 14:30:59 · 360 阅读 · 0 评论 -
32-36
32查询所有任课 ( 在 course 表里有课程 ) 教师的 name 和 department 。用到子查询select name,department from teacher where no in(select t_no from course);±-------±----------------+| name | department |±-------±--...原创 2019-12-16 10:11:31 · 224 阅读 · 0 评论 -
复制表的数据作为条件查询
31.查询成绩比该课程平均成绩低的同学的成绩表查询平均分 select c_no,avg(degree) from score group by c_no;±------±------------+| c_no | AVG(degree) |±------±------------+| 3-105 | 87.6667 || 3-245 | 76.3333 |...原创 2019-12-16 09:53:09 · 275 阅读 · 0 评论 -
23-30
23.查询95033班和95031班全体学生的记录select * from student where class in('95031','95033') order by class;24.查询存在85分以上成绩的课程c_noselect * from score where degree>85;25.查出所有’计算机系’ 教师所教课程的成绩表思路是 先找出course 表...原创 2019-12-15 20:57:13 · 286 阅读 · 0 评论 -
多表查询
22.查询选修课程的同学人数多余 5 人的教师姓名说实话拿到这个问题空想是没有思路的因为已经猜到了是多表查询所以我们一步步来select * from teacher;±----±-------+| no | name |±----±-------+| 804 | 李诚 || 825 | 王萍 || 831 | 刘冰 || 856 | 张旭 |±--...原创 2019-12-14 22:22:11 · 154 阅读 · 0 评论 -
year函数+子查询
20.查询所有学号为108、101的同学同年出生的所有学生的no 、name 、birthday 列。year():选取日期的年份select no,name,birthday from student where year(birthday) in (select year(birthday) from student where no in(101,108));这个语句也用到了子查询...原创 2019-12-14 11:42:51 · 558 阅读 · 1 评论 -
求平均分+子查询
17.查询班级是’95031’班学生每门课的平均分用到分组group by;select c_no,avg(degree) from scorewhere s_no in (select no from student where class='95031')group by c_no;再解释一下为什么要用in,可以这么说,in包含等于而最后本题中no的个数不止一个所以用in18....原创 2019-12-14 11:32:47 · 758 阅读 · 0 评论 -
13-16题(包含多表查询)
13 查询分数大于70但是小于90的s_no列:select s_no,degree from score where degree>70 and degree <90;14.查询所有的学生 name , c_no, degree列 select name,c_no, degree from student ,score where student.sno=score.s_n...原创 2019-12-13 09:58:50 · 184 阅读 · 0 评论 -
分组条件与模糊查询
12,查询score表中至少有2名学生选修的,并且以3开头的课程的平均分这个东西用到好多复合语句我们一步一步来select *from score;得到表格±-----±------±-------+| s_no | c_no | degree |±-----±------±-------+| 103 | 3-105 | 92 || 103 | 3-245 | ...原创 2019-12-12 22:10:23 · 223 阅读 · 0 评论 -
分组计算平均成绩
11.查询每门课的平均成绩select avg(degree) from score where c_no='3-105';select avg(degree) from score where c_no='3-245';select avg(degree) from score where c_no='6-166';但我们可以建立分组来简化计算;select c_no,avg(deg...原创 2019-12-12 22:00:18 · 1135 阅读 · 0 评论 -
查询练习1到10
1、查询 student表中的所有行select *from student;2、查询student 表中的name、class字段的所有行select name,class from student;3、查询teacher表中不重复的department 列;select distinct department from teacher;注意distinct:去重复的意思4、...原创 2019-12-12 12:10:41 · 416 阅读 · 0 评论 -
数据建立
新建一个查询用的数据库:selectTestCREATE DATABASE selectTest;选择该数据库:USE selectTest;学生表:student学号姓名性别出生日期所在班级CREATE TABLE student( s_no VARCHAR(20) PRIMARY KEY COMMENT'学生学号', s_name VARCHAR(20...原创 2019-12-11 22:12:48 · 291 阅读 · 0 评论 -
数据库的三大设计范式
1NF只要字段还能继续拆分,就不能满足第一范式2NF在满足第一范式条件下,其他列必须完全依赖于主键列,如果不完全依赖,只可能是联合主键的情况:订单表create table myoder(product_id int,customer_id int,product_name varchar(20),customer_name varchar(20),primary key(pr...原创 2019-12-10 21:46:38 · 148 阅读 · 0 评论 -
建立约束5外键约束
班级create table classes(id int primary key,name varchar(20));学生表create table students(id int primary key,name varchar(20),class_id int,foreign key(class_id) references classes(id));/FORE...原创 2019-12-10 15:26:07 · 157 阅读 · 0 评论 -
建立约束3 非空约束,4默认约束
– 建表时添加非空约束– 约束某个字段不能为空create table user(id int,name varchar(20) not null);– 移除非空约束alter table user modify name varchar(20);原创 2019-12-09 22:17:04 · 502 阅读 · 0 评论 -
建立约束2唯一约束
创建唯一键create TABLE user(id int,name varchar(20),UNIQUE(name));– 添加唯一主键– 如果建表时没有设置唯一建,还可以通过SQL语句设置(两种方式):alter table user add unique(name);alter table user modify name varchar(20) unique;删除唯...原创 2019-12-09 22:12:22 · 246 阅读 · 0 评论 -
建表约束1主键约束
主键约束使某个字段不重复且不得为空,确保表内数据的唯一性。CREATE TABLE user(id INT PRIMARY KEY,name VARCHAR(20));INSERT INTO user VALUES (1,'张三');+----+------+| id | name |+----+------+| 1 | 张三 |+----+------+运行DESCR...原创 2019-12-09 22:02:33 · 640 阅读 · 0 评论 -
SQL基础知识学习
SQL基础知识退出数据库服务器EXIT;基本语法显示所有数据库Show databases;创建数据库CREATE DATABASE test;切换数据库Use test;显示数据库中的所有表Show tables;创建数据表Create TABLE pet(Name VARCHAR(20),Owner VARCHAR(20),Species VARCHAR(2),...原创 2019-12-05 21:54:54 · 155 阅读 · 0 评论
分享