CREATE TABLE `city` (
`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
`city_name` VARCHAR(100) COMMENT '城市名',
`city_year` VARCHAR(4) COMMENT '年份,yyyy',
`city_gdp` DOUBLE COMMENT '当前年份,城市一整年的GDP,单位亿元',
`city_population` DOUBLE COMMENT '当前年丰,城市的总人口,单位万人'
);
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);
SELECT COUNT(*) FROM city WHERE city_year = '2019';
SELECT MAX(city_gdp) FROM city WHERE city_year = '2018';
SELECT MIN(city_gdp) FROM city WHERE city_year = '2018';
SELECT SUM(city_gdp) FROM city WHERE city_year = '2019';
SELECT AVG(city_gdp) FROM city WHERE city_year = '2019';
MySQL DDL 语句
MySQL CRUD 语句
MySQL 聚合函数
MySQL 多表查询