-- 建立一个students的表,id为主键
create table students(
id int primary key auto_increment,
name varchar(20) not null,
age int not null,
gender varchar(1) not null
);
-- 向表中赋值
insert into students(name,age,gender) values
('小红','1','女'),
('小蓝','1','男'),
('小刚','2','男'),
('小黄','2','女'),
('小橙','3','女');
-- 统计表中共有多少条记录
select count(*) from students;
-- 年龄之和
select sum(age) from students;
select sum(age/2) from students;
-- 因为字符串不是数字,所以虽然有结果,但是没有意义
select sum(name) from students;
-- 平均值
select avg(age) from students;
select max(age) from students;
select min(age) from students;
-- 总数
select count(distinct age) from students;
select max(distinct age)from students;