数据库是数据存储的集合,表是数据结构化的信息。
列——组织信息
行——明细记录
主键是表中的唯一标示,主键不具备业务意义。
数据库的要求:
表的主键——建议设立
主键值必须唯一,每行必须有一个主键,不可为空
主键值不可被修改,主键值被删除后不可重用
表A的主键,可以做为表B的字段,此时不受约束
数据库字段类型:
”T“ char 文本 ”i“ int 数字 ”%“ float 小数 date 日期 timestamp 时段
基本操作: export 生成 import导入
数据库常用基本语句:
1. select *from data.A(表名);
2. limit 100;(限制100条)order by 列名 (升序) order by 列名 desc(降序)
3. 条件查找 where 列名 = > < != 同<> not in () and or ,同时出现 and优先执行
模糊查找 like "%abc%"
4. group by ABC having count()>= and -针对分组后的结果过滤,多重过滤。
综合 select count(if(,null)) from data.A
group by city
having count(if like "%abc%",null)as x
order by _desc
limit 20
5. 分组清洗
case 同lookup
语法:case when
then
else
end,
6. join left join 同vlookup 范围小于 inner join
join (left right inner )on where or/and
count()不计算空值
7. 时间格式调整
date_add(加)
date_sub(减)
date_format(paidtime,"%y-%m" M英文月份 m中文月份 count(t1,m)当月消费的人数
datediff(max,min)时间差值
ceil 向上取整
8. 加载:
load data local infile "c:/.........utf.csv" into table data._info fields terminated by ',';