当前位置:首页 > Mysql操作笔记
Mysql操作笔记 Update 语句:
Update 表名 set 字段 = 字段新值 where 要修改的某一字段 ; 如图:
Delete 语句 : delete from 表名 where 某一字段值;
Group by 语句:(其作用相当于排序)
select * from 表名 group by 字段名; (默认为升序)
select * from 表名 group by 字段名 desc;(降序)
having语句:(作用是加条件分组,使用having语句设置分组字段时,查询字段中必须有该字段)
或者select * from …
Order by 语句:(作用和 group by 相同)如图
如果有相同值时,设置第二排序条件则:
Select * from 表名 order by 第一字段 , 第二字段 asc /desc ; 如图
Limit 语句,限制返回结果数量
Select * from 表名 group by 字段名 limit 字段名 要输出数量; 如图
Insert ….select 语句 ,将查询的结果查到新表中,(常用)
Insert 表名 select * from 表名; 如图
求平均值: AVG函数;
select AVG (要求字段值) from 表名 ; 如图
四舍五入 round 函数;
Select round (avg(要求字段),2) from 表名;(其中 “,2表示保留几位小数”)如图
子查询与连接
(使用子查询时,括号中的查询语句为子查询,其结果是前面查询要的结果)
例如;select * from 表名 where 字段值 < , >, = … (select ….)
还有直接调用 数值也可以起到同样查询效果;如图
当子查询语句求得多个值时,判断符号只能判断一个值,不加条件会报错,需要用到 Any , some , all 。
select * from 表名 where 字段值 < , >, = … any /some/all (select ….);
共分享92篇相关文档