批改状态:合格
老师批语:
alter table user add age int unsigned not null default 0 comment '年龄' after gender;update user set age= timestampdiff(year,borthday,now());
update user set name='xiaowang' where name='wang';delete from user where id=1;查询数据库
select database()
查询版本
select vsersion()
查询当前时间
select now();
select * from user where id>950;

select name as 姓名,count(1) as数量 from user group by name;
select name 姓名,count(1) 数量 from user group by name;

select * from user where name='li' order by id desc;

从2到3select from user order by age desc limit 2 offset 1;
年龄最大select from user where age=(select max(age) from user);`
select * from user where id>=10 and id <=20;select * from user where id between 10 and 20;

select * from user where id in (1,3,5);
select * from user where name like 'z%';
select * from user where name like '%a%';
select * from user where name like '%g';
select gender ,count(*) from user group by gender;
select gender ,avg(age) 平均年龄 from user group by gender;
select gender ,count(*) from user group by gender having gender='male';
select a.id,a.title,b.name from articles a, cates b where a.cid=b.cid;
select id,title,name from articles a inner join cates b on a.cid=b.cid;//简化select id,title,name from articles a join cates b using(cid);//过滤select id,title,name from articles a inner join cates b on a.cid=b.cid where a.cid=1;

select * from articles a left join cates b on a.cid=b.cid;
select * from articles a right join cates b on a.cid=b.cid;
select * from articles a left join cates b on a.cid=b.cid where a.cid is not null;
select id,title,name from articles natural join cates;
create view v_user as select * from user;
create view vc_user as select name,age from user;select * from vc_user;
update vc_user set age =40 where name='wang';
查询索引
//普通索引create index age on user(age);//唯一索引create unique index unique_age on user(age);//主键索引alter table user add primary key id(id);
show index from user;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号