SQL 中的探索性数据分析
Christina Maimone
Data Scientist
character(n) 或 char(n)
ncharacter varying(n) 或 varchar(n)
ntext 或 varchar
分类数据
Tues, Tuesday, Mon, TH
shirts, shoes, hats, pants
satisfied, very satisfied, unsatisfied
0349-938, 1254-001, 5477-651
red, blue, green, yellow
非结构化文本
I really like this product. I use it every day. It's my favorite color.
We've redesigned your favorite t-shirt to make it even better. You'll love...
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal...
SELECT category, -- 分类变量
count(*) -- 统计每个类别的行数
FROM product -- 表
GROUP BY category; -- 分类变量
category | count
----------+-------
Banana | 1
Apple | 4
apple | 2
apple | 1
banana | 3
(5 rows)
SELECT category, -- 分类变量
count(*) -- 统计每个类别的行数
FROM product -- 表
GROUP BY category -- 分类变量
ORDER BY count DESC; -- 先显示最常见的值
category | count
----------+-------
Apple | 4
banana | 3
apple | 2
Banana | 1
apple | 1
(5 rows)
SELECT category, -- 分类变量
count(*) -- 统计每个类别的行数
FROM product -- 表
GROUP BY category -- 分类变量
ORDER BY category; -- 按分类变量排序
category | count
----------+-------
apple | 1
Apple | 4
Banana | 1
apple | 2
banana | 3
(5 rows)
-- 结果
category | count
----------+-------
apple | 1
Apple | 4
Banana | 1
apple | 2
banana | 3
(5 rows)
-- 字母序:
' ' < 'A' < 'a'
-- 从结果得出
' ' < 'A' < 'B' < 'a' < 'b'
区分大小写
`'apple' != 'Apple'`
空格算数
`' apple' != 'apple'`
空字符串不等于 null
`'' != NULL`
标点差异
`'to-do' != 'to–do'`
SQL 中的探索性数据分析