1、创建数据表——DDL
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`createDate` datetime DEFAULT NULL COMMENT '创建时间',
`userName` varchar(20) DEFAULT NULL COMMENT '用户名',
`pwd` varchar(36) DEFAULT NULL COMMENT '密码',
`phone` varchar(11) DEFAULT NULL COMMENT '手机号',
`age` tinyint(3) unsigned NOT NULL COMMENT '年龄',
`sex` char(2) DEFAULT NULL COMMENT '性别',
`introduce` varchar(255) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
2、插入数据·——DML
INSERT INTO `student` VALUES (1, '2024-02-25 10:10:10', '盘古', '123456', '18630412298', 255, '神', '开天劈地第一人。');
INSERT INTO `student` VALUES (2, '2024-02-25 10:10:10', '女娲', '123456', '18630412298', 200, '女', '多次造人最终成功。');
INSERT INTO `student` VALUES (3, '2024-02-25 10:10:10', '伏羲', '123456', '18630412298', 215, '神', '先天八卦');
INSERT INTO `student` VALUES (4, '2024-02-25 10:10:10', '神农', '123456', '18630412298', 155, '男', '尝百草,死于断肠草下。');
INSERT INTO `student` VALUES (5, '2024-02-25 10:10:10', '嫘祖', '123456', '18630412298', 115, '神', '教会百姓养蚕织布。');
INSERT INTO `student` VALUES (6, '2024-02-25 10:10:10', '蚩尤', '123456', '18630412298', 155, '男', '锻造大神,坐下食铁巨兽。');
INSERT INTO `student` VALUES (7, NULL, '仓颉', NULL, NULL, 125, NULL, '中国象形文字');
INSERT INTO `student` VALUES (8, '2024-02-25 10:10:10', '盘古', '123456', '18630412298', 255, '神', '开天劈地第一人。');
INSERT INTO `student` VALUES (9, '2024-02-25 10:10:10', '女娲', '123456', '18630412298', 200, '女', '多次造人最终成功。');
INSERT INTO `student` VALUES (10, '2024-02-25 10:10:10', '伏羲', '123456', '18630412298', 215, '神', '先天八卦');
INSERT INTO `student` VALUES (11, '2024-02-25 10:10:10', '神农', '123456', '18630412298', 155, '男', '尝百草,死于断肠草下。');
INSERT INTO `student` VALUES (12, '2024-02-25 10:10:10', '嫘祖', '123456', '18630412298', 115, '神', '教会百姓养蚕织布。');
INSERT INTO `student` VALUES (13, '2024-02-25 10:10:10', '蚩尤', '123456', '18630412298', 155, '男', '锻造大神,坐下食铁巨兽。');
INSERT INTO `student` VALUES (14, NULL, '仓颉', NULL, NULL, 125, NULL, '中国象形文字');
3、聚合函数
# 5个常用的聚合函数count(x),max(x),min(x),sum(x),avg(x);
select count(*) from student where pwd is not null;
select max(age) '最大年龄',min(age)'最小年龄' from student;
select sum(age) '总年龄' from student;
select avg(age) '平均年龄' from student;
# 利用sum单独计算一下平均数
select sum(age)/(select count(*) from student) 'sum计算平均年龄' avg(age) '平均年龄' from student;
标签:10,聚合,函数,INSERT,INTO,几种,VALUES,student,NULL
From: https://blog.csdn.net/zilikew/article/details/137145291