数据库的SQL语句:
连接数据库:mysql -u root -p
显示所有数据库: Show databases:
选择数据库:use数据库名字
:显示表:Show tables
数据库的基本操作:增删改查
查询语句:select 字段名1,字段名2…… from 表名;(先选择数据库)
select 字段名1,字段名2…… from 表名 where 条件1 and 条件2;(有查询条件)
插入语句:insert into +表名+(字段名)values(具体值);
ins e r t into t_s tudent ( id, sna m e , age ,phon e ,xue l i ) va lue s (12, '武艺 ’ ,21, ‘1455456564 5’ , '本科 ’ ) ;
修改语句:update 表名 set 字段1=值1,…… where 条件;
删除语句:delete from 表名 where 条件;
多表联查:不同的表之间必须有关系
联:将多张表关联在一起:select 需要显示的字段 from 表1 join 表2 on 表关系 join 表3 on 表关系
s e l e c t t_s tudent . id, sna m e , chine s e , m a th, e n gl i sh f rom t_s tudent join t_gr ade on t_s t u dent . id = t_gr ade . s id;
查:在联的基础上+where 条件1 and 条件2
MySQL常用命令:
模糊查询like:where sname like ‘刘%‘;姓刘的
Where sname like ‘%三%’; 名字中间带三
Where sname like ‘%三‘; 以三结尾
只支持字符串’
排序:order by age 从小到大排序
order by age desc 倒序
一共有几行数据 select count(*) from +表名
重命名:as select count(*) as ‘新表名’ from +表名 as可省略不写
Min:select min(age) from 表名
Max
sum
分组: group by 按照不同的组来做计算,无法分组的去掉(姓名之类的)