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 …