Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:数据表名称推荐使用复数,例如users,每一条记录可用user表示,这是惯例
update user set age = timestampdiff(year, brithdy, now());
select * from user;
select * from user where id = 1;
select * from user where id between 1 and 5;
select * from user where id in(1,2,4,5);
//count()
select gender, count(*) from user group by gender;
//sum()
select sum(age) from user;
//avg()
select avg(age) from user;
select gender, count(*) from user group by gender having gender = 'male';
select * from user order by age desc;
select * from user order by age desc limit 5;
select u.id,u.name,t.id,t.name from user as u, test as t where u.id = t.id;
//简化
select * from user u join test t on u.id = t.id;
//简化
select * from user u join test t using(id);
//条件
select * from user u join test t using(id) where u.id = 1;
select * from user u left join test t using(id);
select * from user u right join test t using(id);
索引应该创建在经常被查询的字段,或者常出现在结果集中的字段上
//普通索引
create index i_name on user (name);
//唯一索引
create unique index unique_gender on user(gender);
prepare stmt from 'select id,name from user where age > ? limit ?';
set @age= 20, @num = 5;
execute stmt using @age, @num;