-- order by 索引
select id,address,phone from user order by id desc;
结果:
注意:
默认索引为升序(asc)倒叙(desc)
代码块:
-- 分页limit
-- 第一页
select * from user limit 0,2;
-- 第二页
select * from user limit 2,4;
-- 第三页
select * from user limit 4,6;
结果图:
!重点:
分页公式:(页码 - 1) X每页条数
goods表:
user和shop表前几次已经创建完毕-- 插入数据goods
insert into goods (goods_num,goods_price,user_id,shop_id)
values
(2,100,1,1),
(1,100,2,1),
(3,50,3,2),
(4,300,1,3);
多表连接:
--- 多表联查
select u.username,u.address,s.shop_name,g.goods_num,g.goods_price from goods g
left join user u on g.user_id=u.id
left join shop s on g.shop_id=s.id where u.id=1;
结果图:
select * from user where username like "%明%";
select * from user where username like "张%";
select * from user where username like "%红";
注意:_ 段横杠是一个占位符
select * from user where username like "_三%";
注意:
\ 是转义字符!!!
个人理解
:事务即是两人同时访问一个文件,且修改时,事务便是会令一个人修改完并提交修改后,第二个人才能在其基础上修改,(在第一个人修改未提交之前,后者一直处于挂起状态),不能够同时修改。