数据库种类分为两大类,关系型数据库与非关系型数据库,重要区分为是否有严格库表结构,关系型数据库都是提前订好的表结构,而redis这种非关系数据库存储在内存当中,获取内存数据更快所以可以作为数据缓存使用。
sql类型主要分为 数据查询语言与数据操纵语言
创建表 create table 表明 (列名1 数据类型,列名2 数据类型,列名3 数据类型)
插入数据 insert into 表明 values(值1,值2,值3)
指定列插入数据 insert into 表明 (列1,列2,列3) values(值1,值2,值3)
查询所有数据 select * from 表1
查询需要列的数据 select 列1,列2 from 表1
根据条件查询 select 列1 from 表1 where 条件
多条件查询 select * from 表1 where 条件1 and 条件2 select * from 表1 where 条件1 or 条件2
排序 select *from 表1 order by 列1 desc 默认asc升序,desc降序
更新表中数据 update 表1 set 列1=新值 where 列1=值1
删除数据 delete from 表1 where 列1=值
清楚表信息不动表结构 truncate table 表1
like 模糊查询 select * from 表1 where 列1 like 值 1开头的写法为‘1%’,带有1的写法‘%1%’
in在选定中的值 select * from 表1 where 列1 in (值1,值2,值3)
between选取区间数据 select * from 表1 where 列1 between 值1 and 值2
as别名 select 列1 as 新名 from 表1 select 列1 from 表1 as 新名
join多表连接
join;inner join;left join;right join;full join;
常用left join左外连接,可以防止丢失数据
例如:select *from a left join b on 连接条件
union合并结果集 select * from a union select * from b
查询某个值非空的数据 select * from a where b is not null
创建视图 create view 名称 as select 列 from 表 where 查询条件
删除视图 drop view 视图名称
函数学习 avg平均值 count汇总行数 max最大值 min最小值 sum求和 group by 分组 having作为函数使用的地方 upper大写 lower小写 length获取长度 round四舍五入 now系统时间
例:select a from b where c='Beijing' group by d having count(city) > 1;