INSERT INTO USER VALUES(2,'小二',12);INSERT INTO USER VALUES(3,'张三',33);INSERT INTO USER VALUES(4,'李四',24);INSERT INTO USER VALUES(5,'王五',17);INSERT INTO USER VALUES(6,'赵六',36);INSERT INTO USER VALUES(7,'七七',18);
完成后 表名 user 表数据:
1.2学生表
CREATE TABLE `students`(`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '学生id(主键)',`name` VARCHAR(10) COMMENT '学生姓名', `grade` VARCHAR(10) COMMENT '学生年级',`chinese` INT COMMENT '语文成绩',`math` INT COMMENT '数学成绩',`english` INT COMMENT '英语成绩');
插入数据
INSERT INTO students VALUES(1,'迪丽热巴','二年级',100,100,100);INSERT INTO students VALUES(2,'古力娜扎','一年级',99,88,98);INSERT INTO students VALUES(3,'马尔扎哈','三年级',46,20,99);INSERT INTO students VALUES(4,'阿里巴巴','一年级',78,81,100);INSERT INTO students VALUES(5,'哈哈哈哈','六年级',20,10,5);INSERT INTO students VALUES(6,'作者本人','二年级',100,100,100);INSERT INTO students VALUES(7,'嘻嘻哈哈','五年级',70,99,60);INSERT INTO students VALUES(8,'哭哭啼啼','四年级',33,15,54);
INSERT INTO city VALUES(1,'上海',2018,32679,2418);INSERT INTO city VALUES(2,'北京',2018,30320,2171);INSERT INTO city VALUES(3,'深圳',2018,24691,1253);INSERT INTO city VALUES(4,'广州',2018,23000,1450);INSERT INTO city VALUES(5,'重庆',2018,20363,3372);INSERT INTO city VALUES(6,'上海',2019,38155,2424);INSERT INTO city VALUES(7,'北京',2019,35371,2171);INSERT INTO city VALUES(8,'深圳',2019,26927,1302);INSERT INTO city VALUES(9,'广州',2019,23628,1491);INSERT INTO city VALUES(10,'重庆',2019,23605,3372);
COUNT 查询计算2019年一共有多少个城市录入数据(答案 5个)
SELECT COUNT(*) FROM city WHERE city_year = '2019';
MAX 查询 2018年里 GDP 最高是多少;
SELECT MAX(city_gdp) FROM city WHERE city_year = '2018';
MIN 查询 2018年里 GDP 最低是多少;
SELECT MIN(city_gdp) FROM city WHERE city_year = '2018';
SUM 查询2019年里所有城市 GDP 总和;
SELECT SUM(city_gdp) FROM city WHERE city_year = '2019';
AVG 查询2019年所有城市 GDP 平均值;
SELECT AVG(city_gdp) FROM city WHERE city_year = '2019';
3.增加
insert into 表名(字段1,字段2,字段3,…)values(值1,值2,值3,…);
添加学生鸡鸡鸡鸡
INSERT INTO students(id,NAME,grade,chinese,math,english) VALUES( 9,'鸡鸡鸡鸡','七年级',77,77,77);
其它插入方式
INSERT INTO 表名(字段1,字段2,字段3) VALUES (值1,值2,值3),(值1,值2,值3); -- 插入多条数据INSERT INTO 表名 VALUES(值1,值2); -- 针对表全字段进行插入操作INSERT INTO 表名(字段) SELECT 字段 FROM 表2; -- 查询结果插入INSERT INTO 表名 SELECT 字段 FROM 表2; -- 查询结果,全表插入
4.更新
update 表名 set 字段=值 where 条件; -- 带条件的去修改指定数据,否则修改全表;
修改学生 ‘哈哈哈哈' 的英语成绩为 10;
UPDATE students SET english = 10 WHERE `name` = '哈哈哈哈';
5.删除
delete from 表名 where 条件; -- 删除数据带条件删除,否则删除全表的数据
删除学生 ‘鸡鸡鸡鸡' ;
DELETE FROM students WHERE `name` = '鸡鸡鸡鸡';
6.语句执行顺序
from -> on -> join -> where -> group by -> having -> select -> distinct -> order by -> limit