查询 : 在sql语句 表名和字段名加上'' 加快sql语句的运行速度
select 字段,字段 from 表名
select 'name','title' from 'liuyanban' 查询liuyanban表中name和title字段
select * from 'liuyanban' 查询liuyanban表中所有字段 *代表所有
select * from 'liuyanban' where 'id'=2 查询liuyanban表中 id=2的数据
select * from 'liuyanban' where 'id'<>2 查询liuyanban表中 id不等于2的数据
select * from 'liuyanban' where 'id'!=2 查询liuyanban表中 id不等于2的数据
select * from 'liuyanban' where 'id'<2 查询liuyanban表中 id小于2的数据
select * from 'liuyanban' where 'id'>2 查询liuyanban表中 id大于2的数据
select * from 'liuyanban' where 'id' in(1,4,3) 查询 liuyanban表中 id 的值在in的()里面的数据
select * from 'liuyanban' where 'id' not in(1,4,3) 查询liuyanban表中id的值不在in()里面的数据
select * from 'liuyanban' where 'id' between 2 and 4 查询liuyanban 表中 id的值在2-4之间
select * from 'admin' where 'name'='admin' and 'pwd'='admin123' and 并且
select * from 'admin' where 'name'='admin' or 'pwd'='admin123' or 或者
select * from 'liuyanban' order by 'time' desc 按照时间的降序排列 desc 降序 asc 升序
select * from 'liuyanban' where 'id' in(1,3,4) order by 'time' desc
如果有where条件 order by 必须放在where条件的后面
select * from 'liuyanban' where 'id' in(1,3,4) order by 'id' desc limit 0,2
where order by limit 顺序不能乱
select count (*) from 'liuyanban' 查询表中总的数据条数
select count(*) as allnum from 'liuyanban' as 取别名
select max(id) from 'liuyanban' 查询表当中最大的id值
最大 最小 平均 求和 同理
添加:
insert into 表名 (字段,字段,字段) value(值1,值2,值3)
insert into 'admin' ('name','pwd') value('root','root123')
修改:
update 表名 set 字段=值1,字段=值2,字段=值3 where 条件
删除:
delete from 表名 where 条件