DHDataHọc

Bộ dữ liệu luyện tập

Sáu bộ dữ liệu quan hệ được dùng lại trong toàn bộ bài luyện và ví dụ bài giảng. Xem cấu trúc bảng, thử truy vấn mẫu rồi chuyển sang luyện tập.

6 bộ dữ liệu · 17 bảng

01Thương mại điện tử

Bán lẻ

Khách hàng, sản phẩm, đơn hàng và chi tiết đơn — bộ dữ liệu chuẩn để luyện JOIN nhiều bảng, doanh thu theo ngành hàng và phân tích đơn hàng.

Cấu trúc bảng

customers

CộtKiểu dữ liệu
idinteger
nametext
emailtext
citytext
signup_datedate
segmenttext

products

CộtKiểu dữ liệu
idinteger
nametext
categorytext
pricenumeric(12, 2)
stockinteger

orders

CộtKiểu dữ liệu
idinteger
customer_idinteger → customers.id
order_datedate
statustext

order_items

CộtKiểu dữ liệu
idinteger
order_idinteger → orders.id
product_idinteger → products.id
quantityinteger
unit_pricenumeric(12, 2)

Truy vấn mẫu

select c.city, count(*) as so_don
from orders o
join customers c on c.id = o.customer_id
where o.status <> 'cancelled'
group by c.city
order by so_don desc;
02SaaS

Thuê bao

Người đăng ký, gói dịch vụ và các lần thanh toán — dùng cho bài toán churn, doanh thu định kỳ và tỷ lệ gia hạn.

Cấu trúc bảng

subscribers

CộtKiểu dữ liệu
idinteger
nametext
signup_datedate
countrytext

subscriptions

CộtKiểu dữ liệu
idinteger
subscriber_idinteger → subscribers.id
plantext
started_ondate
ended_ondate
monthly_pricenumeric(12, 2)

payments

CộtKiểu dữ liệu
idinteger
subscription_idinteger → subscriptions.id
paid_ondate
amountnumeric(12, 2)
statustext

Truy vấn mẫu

select plan, count(*) as so_nguoi_dang_dung
from subscriptions
where ended_on is null
group by plan
order by so_nguoi_dang_dung desc;
03Tài chính

Ngân hàng

Chi nhánh, tài khoản và giao dịch — phù hợp để luyện tổng hợp theo loại giao dịch, số dư và hoạt động theo chi nhánh.

Cấu trúc bảng

branches

CộtKiểu dữ liệu
idinteger
nametext
citytext

accounts

CộtKiểu dữ liệu
idinteger
account_notext
customer_nametext
branch_idinteger → branches.id
opened_ondate
balancenumeric(14, 2)

transactions

CộtKiểu dữ liệu
idinteger
account_idinteger → accounts.id
txn_datedate
typetext
amountnumeric(14, 2)

Truy vấn mẫu

select type, sum(amount) as tong_tien
from transactions
group by type
order by tong_tien desc;
04Vận hành

Nhân sự

Phòng ban và nhân viên với mức lương, chức danh, ngày vào làm — luyện GROUP BY, AVG và so sánh lương giữa các phòng.

Cấu trúc bảng

departments

CộtKiểu dữ liệu
idinteger
nametext

employees

CộtKiểu dữ liệu
idinteger
nametext
department_idinteger → departments.id
titletext
salarynumeric(12, 2)
hire_datedate

Truy vấn mẫu

select d.name as phong_ban, avg(e.salary) as luong_trung_binh
from employees e
join departments d on d.id = e.department_id
group by d.name
order by luong_trung_binh desc;
05Y tế

Bệnh viện

Bệnh nhân và các lần khám với phí, khoa — luyện đếm lượt khám, tổng chi phí và phân tích theo nhóm bệnh nhân.

Cấu trúc bảng

patients

CộtKiểu dữ liệu
idinteger
nametext
dobdate
gendertext
citytext

visits

CộtKiểu dữ liệu
idinteger
patient_idinteger → patients.id
visit_datedate
departmenttext
feenumeric(12, 2)

Truy vấn mẫu

select department, count(*) as so_lan_kham, sum(fee) as tong_phi
from visits
group by department
order by tong_phi desc;
06EdTech

Giáo dục

Học viên, khóa học và lượt ghi danh — luyện tỷ lệ hoàn thành, doanh thu khóa học và phân tích hành vi học tập.

Cấu trúc bảng

edu_students

CộtKiểu dữ liệu
idinteger
nametext
signup_datedate
countrytext

edu_courses

CộtKiểu dữ liệu
idinteger
titletext
pricenumeric(12, 2)

edu_enrollments

CộtKiểu dữ liệu
idinteger
student_idinteger → edu_students.id
course_idinteger → edu_courses.id
enrolled_ondate
completed_ondate

Truy vấn mẫu

select c.title, count(e.student_id) as so_hoc_vien
from edu_courses c
left join edu_enrollments e on e.course_id = c.id
group by c.title
order by so_hoc_vien desc;

Dữ liệu hoạt động thế nào?

  • Mỗi lượt chạy bài dùng một bản sao riêng của bộ dữ liệu, nên bạn có thể thoải mái thử nghiệm mà không sợ làm hỏng dữ liệu gốc.
  • Dữ liệu được tạo lại từ seed script trước mỗi lượt chạy, vì thế kết quả luôn nhất quán giữa các lần.
  • Truy vấn mẫu bên dưới sao chép được vào trang luyện tập và chạy ngay.