1、增加
insert into tableName values(val1,val2,val3) //必须与数据库对应
insert into tableName(columnName1,columnName2) values(val1,val)
2、删除
delete from tableName where columnName=value
delete from tableName where columnName in (%s)
3、修改
update tableName set columnName=value
4、基本查询
//查询所有数据
select * from tableName
//查询某列数据
select column1,column2 from tableName
5、条件查询
//查询大于某字段的数据(时间为例)小于某字段范围内 这里的date为字段名
select * from tableName where date>='2017-3-5' and date<'2018-3-2'
//模糊查询 addre为字段名 查询所有上海的
select * from tableName where addre like '上海%'
//查询男或者女 哈哈,举例
select * from tableName where sex='男' or sex='女'
//查询符合条件的
select * from tableName where name in ('张三','李四','王五')
6、排序
//通过某字段 升序 排序 ps:id为字段名
select * from tableName order by id asc
//通过某字段 降序 排序
select * from tableName order by id desc
7、分组
select * from tablesName group by columnName
//对查询的结果分组 ps:id和sex都是字段
select * from tableName where id>1 group by sex
//having条件查询
select * from tableName where id>1 group by sex having age>12
注意: where跟在from语句之后使用,对查询到的原始数据筛选
having跟在group by语句之后,对分组后的数据进行筛选,否则和wher语句一样
8、关联查询
select column1,column2 from table1,table2 where table1.id=table2.id
9、分页查询
select * from tableName limit x,y
//x:(当前页数-1)*行数
//y:行数
10、函数
//和
select sum(columnName) from tableName
//平均
select avg(columnName) from tableName
//个数
select count(*) from tableName
//注意:不计算null值
//截取查询
select substr(column,x,y) from tableName
//x:起始位置 注意 起始不是0,是1
//y:结束位置
11、为表动态添加字段
//在id字段后添加一条字段
alter table tableName add columnName varchar(255) after id