mysql例子
1 1、1. 建一张学生表 包含( id , name , age , sex ) 2 3 \2. 增加四条数据 4 5 \3. 查询表中 sex 为男的数据 6 7 \4. 删除 id =3 的数据, 8 9 \5. 将 sex 为女的,修改为男 10 11 12 13 create table students(id int, 14 name varchar(20), 15 age int, 16 sex varchar(4)); 17 18 insert into students values(1, "小白", 18, "男"), 19 (2, "小张", 19, "男"), 20 (3, "小红", 20, "女"), 21 (4, "小泼", 21, "女"); 22 23 select * from students where sex = "男"; 24 25 delete from students where id = 3; 26 27 update students set sex = "男" where sex = "女"; 28
1 统计出每个年级分别有多少人 2 3 统计出每个年级age大于18的人数 4 5 统计出一年级的人数 6 7 统计出一年级age大于18的人数 8 9 create table students(id int primary key auto_increment, 10 name varchar(4), 11 age int, 12 grade varchar(20))auto_increment = 201512940; 13 14 insert into students (name, age, grade) values 15 ( '刘一', 16, '一年级'), 16 ( '陈二', 17, '二年级'), 17 ( '张三', 18, '一年级'), 18 ( '李四', 19, '三年级'), 19 ( '王五', 20, '一年级'), 20 ( '赵六', 21, '二年级'), 21 ( '孙七', 22, '一年级'), 22 ( '周八', 23, '一年级'), 23 ( '吴九', 23, '三年级'), 24 ( '郑十', 23, '一年级'); 25 26 select grade, count(name) from students group by grade; 27 28 select grade, count(name) from students where age > 18 group by grade; 29 30 select count(name) from students where grade = "一年级"; 31 32 select count(name) from students where grade = "一年级" and age > 18;