1、插入数据:
insert into 表名(字段1,字段2)values(值1,值2)
2、删除数据:
delete from 表名 where 条件
删除一张表:
drop table 表名
3、修改数据:
update 表名 set 字段=值 where 条件
4、查询数据:
总数:select count(*)from table1 where 范围
去重总数:select count (distinct(字段1) from table1 where 范围(distinct可去重)
求和:select sum (字段1) from table1 where 范围
平均:select avg(字段1) from table1 where 范围
最大:select max(字段1)from table1 where 范围
最小:select min(字段1) from table1 where 范围
排序:select* from table1 where 范围 order by 排序字段名 desc(desc逆序排序。默认是正序排序asc)
5、嵌套查询:
查询重复数据并统计重复数据有多少:select 姓名,count(姓名) from student group by 姓名 having count(姓名)>=2
6、左连接查询:
select * from table1 as a left join table2 as b on a.id=b.id where 条件
7、右连接查询
select * from table1 as a right join table2 as b on a.id=b.id where 条件
8、全连接查询
select * from table1 as a full join table2 as b on a.id =b.id where 条件
9、内连接查询
select * from table1 as a inner join table2 as b on a.id =b.id where 条件
10、分组查询
select * from table group by 字段
11、查询排序
顺序:select * from table order by 字段 asc
倒序:select * from table order by 字段 desc