SQL로 하는 탐색적 데이터 분석
Christina Maimone
Data Scientist
character(n) 또는 char(n)
n 고정character varying(n) 또는 varchar(n)
n까지 가변 길이text 또는 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로 하는 탐색적 데이터 분석