
批改狀態(tài):合格
老師批語:
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;
查詢數(shù)據(jù)庫
select database()
查詢版本
select vsersion()
查詢當(dāng)前時(shí)間
select now();
select * from user where id>950;
select name as 姓名,count(1) as數(shù)量 from user group by name;
select name 姓名,count(1) 數(shù)量 from user group by name;
select * from user where name='li' order by id desc;

從2到3
select 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;
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號