SELECT*FROM stu;INSERTINTO stu ( id, NAME )VALUES(1,'张三');INSERTINTO stu ( id, NAME, sex, birthday, score, email, tel,STATUS)VALUES(2,'李四','男','1999-11-11',88.888,'lisi@itcase.cn','13812345678',1);update stu set sex ='女'where name ='张三';update stu set score ='99.99', birthday='1999-12-12'where name ='张三';deletefrom stu WHERE name ='张三';
DQL - 查询表
基础查询
droptableifEXISTS stu;createtable stu (id int,-- 编号name varchar(20),-- 姓名age int,-- 年龄sex varchar(5),-- 性别address varchar(100),-- 地址math double(5,2),-- 数学成绩english double(5,2),-- 英语成绩hire_date date-- 入学时间);-- 添加数据INSERTINTO stu(id, name, age, sex, address, math, english, hire_date)VALUES(1,'码云',55,'男','杭州',66,78,'1995-09-01'),(2,'麻花藤',45,'男','深圳',98,87,'1998-09-01'),(3,'马斯磕',45,'男','香港',56,77,'1999-09-02'),(4,'留白',20,'女','湖南',76,65,'1997-09-05'),(5,'刘青',20,'男','湖南',86,NULL,'1998-09-01'),(6,'刘德华',57,'男','香港',99,99,'1998-09-01'),(7,'张学右',22,'女','香港',99,99,'1998-09-01'),(8,'德玛西亚',18,'男','南京',56,65,'1994-09-02');select*from stu;CREATEtable stu;showtables;-- 基础查询-- 查询 name, age 两列select name, age from stu;-- 查询所有列的数据,列名的列表select*from stu;-- 查询地址信息select address from stu;-- 去除重复记录selectdistinct address from stu;-- 查询 姓名,数学成绩,英语成绩select name, math as 数学成绩, english as 英语成绩 from stu;
条件查询
-- 条件查询-- 1、查询年龄大于20岁的成员select*from stu where age >20;-- 2、查询年龄大于等于20的学员信息select*from stu WHERE age >=20;-- 3、查询年龄大于等于20 并且 小于等于30 的学员信息select*from stu where age >=20&& age <=30;select*from stu where age >=20and age <=30;select*from stu where age between20and30;-- 4、查询入职日期在 '1998-09-01' 到 '1999-09-01' 之间的学员信息select*from stu where hire_date between'1998-09-01'and'1999-09-01';-- 5、查询年龄等于18岁的学员信息select*from stu where age =18;-- 6、查询年龄不等于18岁的学员信息select*from stu where age !=18;-- 7、查询年龄等于18岁 或者 年龄等于20岁 或者年龄等于22岁的学员信息select*from stu where age =18or age =20or age =22;select*from stu where age in(18,20,22);-- 8、查询英语成绩为null的学员信息select*from stu where english isnull;
模糊查询
-- 模糊查询-- 1、查询姓'马'的学员信息select*from stu where name like'马%';-- 2、查询第二个字是'花'的学员信息select*from stu where name like'_花%';-- 3、查询名字中包含'德'的学员信息select*from stu where name like'%德%';
排序查询
-- 排序查询-- 1、查询学生信息,按照年龄升序排列select*from stu orderBY age ASC;-- 2、查询学生信息,按照数学成绩降序排列select*from stu orderBY math DESC;-- 3、查询学生信息,按照数学成绩降序排列,如果数学成绩一样,再按照英语成绩升序排列select*from stu orderBY math DESC, english asc;
聚合函数
-- 聚合函数-- 1、统计班级一共有多少个学生SELECTcount(id)as 人数 from stu;-- count 统计的列名不能为null-- 2、查询数学成绩的最高分select name,max(math)as 数学分数最高的屌丝 from stu;-- 3、查询数学成绩的最低分select name,min(math)as 数学分数最高的高富帅 from stu;-- 4、 查询数学成绩的总分selectsum(math)as 数学总分 from stu;-- 5、查询数学成绩的平均分selectavg(math)as 数学平均分 from stu;-- 6、查询英语成绩的最低分, 所有null的值不参与计算selectmin(english)from stu;
分组查询
-- 分组查询-- 1、查询男同学和女同学各自的数学平均分select sex,avg(math)from stu groupby sex;-- 2、查询男同学和女同学各自的数学平均分,以及各自人数select sex,avg(math),count(id)from stu groupby sex;-- 3、查询男同学和女同学各自的数学平均分,以及各自人数,要求:分数低于70分的同学不参与分组select sex,avg(math),count(*)from stu where math >=70groupby sex;-- 4、查询男同学和女同学各自的数学平均分,以及各自人数,要求:分数低于70的不参与分组,分组之后人数大于个select sex,avg(math),count(*)from stu where math >=70groupby sex havingcount(*)>2;
分页查询
-- 分页查询-- 1、从0开始查询,查询3条数据select*from stu limit0,3;-- 2、每页显示3条数据,查询第1页数据select*from stu limit0,3;-- 3、每页显示2条数据,查询第2页数据select*from stu limit3,3;-- 4、每页显示3条数据,查询第3页数据select*from stu limit6,3;
1、约束
DROP TABLE IF EXISTS emp;-- 员工表
CREATE TABLE emp (id INT PRIMARY KEY auto_increment, -- 员工id,主键且自增长ename VARCHAR(50) NOT NULL UNIQUE, -- 员工姓名,非空并且唯一joindate DATE NOT NULL, -- 入职日期,非空salary DOUBLE(7, 2) NULL, -- 工资,非空…
题解 直接二分然后建图跑网络流看看是否合法即可 就是源点向每个激光武器连一条二分到的时间激光武器每秒攻击值的边 每个激光武器向能攻击的装甲连一条边 每个装甲向汇点连一条装甲值的边 代码 #include <bits/stdc.h>
#define fi first
#define se second
#define pii …