PHP重点3---表中简单查询增删改
Posted mjwwzy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP重点3---表中简单查询增删改相关的知识,希望对你有一定的参考价值。
1、最简单查询
select * from car;
2、查询指定列
select name,oil,powers from car;
3、对查出的列名修改名字
select name as ‘车名‘,oil as ‘油量‘,powers as ‘动力‘ from car;
4、按条件查询
select name,oil,powers from car where oil = 8.7;
5、多条件查询
select name oil,powers from car where oil = 8.7 or powers = 160;
select name oil,powers from car where oil = 8.7 and powers = 160;
6、范围查询
select * from car where price>=40 and price<=60;
select * from car where price between 40 and 60;
7、离散查询
select * from car where powers = 130 or powers = 150 or powers = 170;
select * from car where powers in(130,150,170);
select * from car where powers not in(130,150,170);
8、模糊查询
select * from car where name like ‘%宝马%‘; %号是所有字符
select * from car where name like ‘_宝马‘ ; _号是一个字符
9、排序查询 asc升序 desc降序 order对结果集进行排序
select * from car order by oil asc;
select * from car order by oil desc;
10、去重复查询 distinct
select distinct brand from car;
11、分页查询
select * from car limit 10,5; 第一个数字表示跳过的条数,第二个数字表示跳过后展示的条数。
n表示页数,m表示每页显示的条数
limit(n-1)*m,m;
12、聚合函数查询
count(列名) 总数的意思
sum(列名) 求和的意思
avg(列名) 平均的意思
max(列名) min(列名)
select count(*) from car;
select sum(price) from car;
select avg(price) from car;
select max(price) from car;
select min(price) from car;
=========================================================================================
增删改
1、添加表中数据
insert into car values(‘‘,‘‘,‘‘,‘‘);
insert into car(字段1,值1) values(字段2,值2);
insert into car set 字符1,值1 vables(字符2,值2);
2、修改表数据
update car set 字段1 = 值 where 字段2(要看字段类型) = 值2
3、删除表数据
delete from 表名 where 字段1 = 值1
以上是关于PHP重点3---表中简单查询增删改的主要内容,如果未能解决你的问题,请参考以下文章