批改状态:合格
老师批语:非常棒,要多写多看

-- 增insert users (name,gender,salary,email,birthday)values ('php','male',888,'php@php.cn','1993-08-03'),('cn','male',888,'php@php.cn','1993-08-03');-- 删delete from users where name = 'cn';-- 改 将users库中name值为php的改为helloworldupdate users set name = 'helloworld' where name = 'php';-- 查select name,gender,email,salary from users where name = 'helloworld';

-- 条件查询:查询salary大于8000的用户select sid,name,salary from users where salary>8000;

-- 区间查询:salary > 6000 salary <= 8000;select sid,name,salary from users where salary > 6000 and salary <= 8000;

-- 分组查询:按性别分组查询,统计数量select gender 性别, count(*) 数量 from users group by gender;

-- 排序查询:按年龄降序排序select sid,name,age,salary from users order by age desc limit 5;

-- 分页查询:每页显示五条记录,查询第二页,偏移量公式:offset = (2-1) * 5 = 5select sid,name,email from users limit 5 offset 5;

-- 集合查询:查询id为35,38,40select sid,name,salary from users where sid in (35,38,40);

-- 模糊查询:查询名称第二个带o的用户select sid,name,salary from users where name like '_o%';

-- 分组过滤查询:按性别分组查询,num统计数量,过滤条件为男性select gender, count(*) num from users group by gender having gender = 'female';


-- 内连接使用joinselect a.aid,title,namefrom articles a join categories cusing(cid);-- 关联查询select a.aid,title,name from articles a, categories c where a.cid = c.cid;-- 左外连接:左主表,右从表select *from articles aleft join categories con a.cid = c.cid;-- 右外连接:右主表,左从表select *from articles aright join categories con a.cid = c.cid;

-- 生成预处理的sql语句prepare stmt from 'select sid,name,salary from users where salary > ? limit ?';-- 将真实的数据绑定到预处理语句的占位符set @salary=5000, @num=2;execute stmt using @salary, @num;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号