1、DDL
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`creatDate` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`userName` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名',
`pwd` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码',
`phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机号',
`age` tinyint(3) UNSIGNED NULL DEFAULT NULL COMMENT '年龄',
`sex` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`intrduce` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
2、DML
INSERT INTO `student` VALUES (1, '2024-02-25 10:10:10', '盘古', '123456', '15612345678', 255, '神', '123');
INSERT INTO `student` VALUES (2, '2024-02-25 10:10:10', '女娲', '123456', '15612345678', 200, '女', '123');
INSERT INTO `student` VALUES (3, '2024-02-25 10:10:10', '伏羲', '123456', '15612345678', 255, '神', '123');
INSERT INTO `student` VALUES (4, '2024-02-25 10:10:10', '神农', '123456', '15612345678', 255, '男', '123');
INSERT INTO `student` VALUES (5, '2024-02-25 10:10:10', '嫘祖', '123456', '15612345678', 255, '神', '123');
INSERT INTO `student` VALUES (6, '2024-02-25 10:10:10', '蚩尤', '123456', '15612345678', 255, '男', '123');
INSERT INTO `student` VALUES (7, NULL, '仓颉', NULL, NULL, 123, NULL, '123');
3、聚合函数
select count(*)from student where pwd is null;
select max(age) '最大年龄',min(age)'最小年龄'from student;
select sum(age)'总年龄'from student;
select avg(age)'平均年龄'from student;
select sum(age)/(select count(*)from student)'sum计算平均年龄',avg(age)'平均年龄'from student;