Mysql数据库第二天
1.修改数据
upadte 表名 set 新 where 条件
2.删除数据
delete from 表名 只删除表数据,不删除表约束
truncate from 表名 可以删除表数据,也可以删除表约束
3.查询数据
select * from 表名 查询所有数据
select 列名 from 表名 查询指定列数据
select 列名 as '常量名' from 表名 查询时添加常量名
select 列名+列名 from 表名 查询时合并列
select distinct 列名 from 表名 查询时去除重复记录
4.条件查询
select * from 表名 where 条件
select * from 表名 where 条件1 and 条件2 查询时条件交集
select * from 表名 where 条件1 or 条件2 查询时条件并集
比较条件:< > >= <= <>(不等于) between and
select * from 表名 where 分数 between 80 and 90 查询分数在80-90之间的学生信息
判空条件:is null表示没有值 is not null 不是空 ="" <>
模糊查询:select * from 表名 where name like '张%' 查询姓张的同学信息
select * from 表名 where name like '__" 查询名字是两个字的同学信息
聚合查询:
查询总成绩: select sum(分数) from 表名
查询平均分:select avg(分数)from 表名
查询最高分:select max(分数) from 表名
查询最低分:select min(分数) from 表名
查询总人数:select count(*) from 表名
分页查询:
select * from 表名 limit 0,2
-- 起始行从0开始
-- 分页:当前页 每页显示多少条
-- 分页查询当前页的数据的sql: SELECT * FROM student LIMIT (当前页-1)*每页显示多少条,每页显示多少条;
查询排序:
select * from 表名 order by 列名 asc 升序
select * from 表名 order by 列名 desc 降序
分组查询:
select 列名1 from 表名 group by 列名1 having 条件