Phân tích Khám phá Dữ liệu bằng SQL
Christina Maimone
Data Scientist
character(n) hoặc char(n)
ncharacter varying(n) hoặc varchar(n)
ntext hoặc varchar
Phân loại (Categorical)
Tues, Tuesday, Mon, TH
shirts, shoes, hats, pants
satisfied, very satisfied, unsatisfied
0349-938, 1254-001, 5477-651
red, blue, green, yellow
Văn bản không cấu trúc
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, -- biến phân loại
count(*) -- đếm số dòng cho mỗi hạng mục
FROM product -- bảng
GROUP BY category; -- biến phân loại
category | count
----------+-------
Banana | 1
Apple | 4
apple | 2
apple | 1
banana | 3
(5 rows)
SELECT category, -- biến phân loại
count(*) -- đếm số dòng cho mỗi hạng mục
FROM product -- bảng
GROUP BY category -- biến phân loại
ORDER BY count DESC; -- hiển thị giá trị xuất hiện nhiều nhất trước
category | count
----------+-------
Apple | 4
banana | 3
apple | 2
Banana | 1
apple | 1
(5 rows)
SELECT category, -- biến phân loại
count(*) -- đếm số dòng cho mỗi hạng mục
FROM product -- bảng
GROUP BY category -- biến phân loại
ORDER BY category; -- sắp xếp theo biến phân loại
category | count
----------+-------
apple | 1
Apple | 4
Banana | 1
apple | 2
banana | 3
(5 rows)
-- Kết quả
category | count
----------+-------
apple | 1
Apple | 4
Banana | 1
apple | 2
banana | 3
(5 rows)
-- Thứ tự chữ cái:
' ' < 'A' < 'a'
-- Từ kết quả
' ' < 'A' < 'B' < 'a' < 'b'
Phân biệt chữ hoa/thường
'apple' != 'Apple'
Khoảng trắng có ý nghĩa
' apple' != 'apple'
'' != ' '
Chuỗi rỗng không phải null
'' != NULL
Khác biệt dấu câu
'to-do' != 'to–do'
Phân tích Khám phá Dữ liệu bằng SQL