# ĐỀ TEST SQL – CHỦ ĐỀ: QUẢN LÝ Y TẾ

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Thời gian làm bài: 90 phút  
  
🎯 Mục tiêu đánh giá:  
\- Viết SQL chính xác  
\- Hiểu nghiệp vụ y tế  
\- Phát hiện dữ liệu bất thường  
\- Tư duy kiểm thử dữ liệu  
  
  
</span>

## <a name="_c47ki188yoz5"></a>**<span lang="vi" style="font-size: 13.0pt; line-height: 87%; color: #4f81bd;">I. MÔ TẢ HỆ THỐNG &amp; CSDL</span>**

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Giả định DB: MySQL / PostgreSQL</span>

<span lang="vi" style="font-family: Andika; mso-fareast-font-family: Andika; mso-bidi-font-family: Andika;">1️⃣ Bảng patients  
patients (  
<span style="mso-tab-count: 1;"> </span>id BIGINT PRIMARY KEY,  
<span style="mso-tab-count: 1;"> </span>patient\_code VARCHAR(20),  
<span style="mso-tab-count: 1;"> </span>full\_name VARCHAR(100),  
<span style="mso-tab-count: 1;"> </span>gender VARCHAR(10),  
<span style="mso-tab-count: 1;"> </span>date\_of\_birth DATE,  
<span style="mso-tab-count: 1;"> </span>phone VARCHAR(20),  
<span style="mso-tab-count: 1;"> </span>status VARCHAR(20),  
<span style="mso-tab-count: 1;"> </span>created\_at TIMESTAMP  
)  
  
  
</span>

<span lang="vi" style="font-family: Andika; mso-fareast-font-family: Andika; mso-bidi-font-family: Andika;">2️⃣ Bảng doctors  
doctors (  
<span style="mso-tab-count: 1;"> </span>id BIGINT PRIMARY KEY,  
<span style="mso-tab-count: 1;"> </span>doctor\_code VARCHAR(20),  
<span style="mso-tab-count: 1;"> </span>full\_name VARCHAR(100),  
<span style="mso-tab-count: 1;"> </span>specialty VARCHAR(100),  
<span style="mso-tab-count: 1;"> </span>department VARCHAR(100),  
<span style="mso-tab-count: 1;"> </span>status VARCHAR(20)  
)  
  
  
</span>

<span lang="vi" style="font-family: Andika; mso-fareast-font-family: Andika; mso-bidi-font-family: Andika;">3️⃣ Bảng appointments  
appointments (  
<span style="mso-tab-count: 1;"> </span>id BIGINT PRIMARY KEY,  
<span style="mso-tab-count: 1;"> </span>patient\_id BIGINT,  
<span style="mso-tab-count: 1;"> </span>doctor\_id BIGINT,  
<span style="mso-tab-count: 1;"> </span>appointment\_date DATE,  
<span style="mso-tab-count: 1;"> </span>appointment\_time TIME,  
<span style="mso-tab-count: 1;"> </span>status VARCHAR(20)  
)  
  
  
</span>

<span lang="vi" style="font-family: Andika; mso-fareast-font-family: Andika; mso-bidi-font-family: Andika;">4️⃣ Bảng medical\_records  
medical\_records (  
<span style="mso-tab-count: 1;"> </span>id BIGINT PRIMARY KEY,  
<span style="mso-tab-count: 1;"> </span>patient\_id BIGINT,  
<span style="mso-tab-count: 1;"> </span>doctor\_id BIGINT,  
<span style="mso-tab-count: 1;"> </span>diagnosis TEXT,  
<span style="mso-tab-count: 1;"> </span>visit\_date DATE,  
<span style="mso-tab-count: 1;"> </span>note TEXT  
)  
  
  
</span>

<span lang="vi" style="font-family: Andika; mso-fareast-font-family: Andika; mso-bidi-font-family: Andika;">5️⃣ Bảng prescriptions  
prescriptions (  
<span style="mso-tab-count: 1;"> </span>id BIGINT PRIMARY KEY,  
<span style="mso-tab-count: 1;"> </span>medical\_record\_id BIGINT,  
<span style="mso-tab-count: 1;"> </span>medicine\_name VARCHAR(100),  
<span style="mso-tab-count: 1;"> </span>dosage VARCHAR(50),  
<span style="mso-tab-count: 1;"> </span>days INT  
)  
  
  
</span>

## <a name="_5hk23cphpc08"></a>**<span lang="vi" style="font-size: 13.0pt; line-height: 87%; color: #4f81bd;">II. PHẦN A – SQL CƠ BẢN</span>**

<span lang="vi" style="font-family: Cardo; mso-fareast-font-family: Cardo; mso-bidi-font-family: Cardo;">⏱ Thời gian gợi ý: 35–40 phút</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 1: Danh sách bệnh nhân đang hoạt động  
Lấy patient\_code, full\_name, gender, status của bệnh nhân có status = 'active'.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 2: Lịch hẹn khám và bác sĩ  
Liệt kê patient\_code, patient\_name, doctor\_name, specialty, appointment\_date, status.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 3: Số lượng bác sĩ theo khoa  
Thống kê số lượng bác sĩ theo department.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 4: Lịch sử khám của bệnh nhân  
Với patient\_code = 'BN001', liệt kê visit\_date, doctor\_name, diagnosis.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 5: Số lượt khám của mỗi bệnh nhân  
Đếm số bản ghi medical\_records của từng bệnh nhân.</span>

## <a name="_qaubjy7pr0ra"></a>**<span lang="vi" style="font-size: 13.0pt; line-height: 87%; color: #4f81bd;">III. PHẦN B – SQL NÂNG CAO</span>**

<span lang="vi" style="font-family: Cardo; mso-fareast-font-family: Cardo; mso-bidi-font-family: Cardo;">⏱ Thời gian gợi ý: 50–55 phút</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 6: Bệnh nhân chưa từng đi khám  
Liệt kê bệnh nhân không có bản ghi trong medical\_records.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 7: Bác sĩ có lịch hẹn bị hủy  
Liệt kê bác sĩ có ít nhất 1 lịch hẹn status = 'canceled'.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 8: Bác sĩ khám nhiều bệnh nhân nhất  
Tìm bác sĩ có số lượt khám nhiều nhất.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 9: Lần khám gần nhất của mỗi bệnh nhân  
Lấy patient\_code, last\_visit\_date, doctor\_name, diagnosis.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 10: Phát hiện dữ liệu bất thường  
Liệt kê appointments có patient\_id không tồn tại và prescriptions có medical\_record\_id không tồn tại.</span>

<span lang="vi" style="font-family: 'Times New Roman',serif; mso-fareast-font-family: 'Times New Roman';">Câu 11 (Bonus): Tư duy hệ thống  
1\. Nên index những cột nào?  
2\. Vì sao không nên lưu tổng số lượt khám trong bảng patients?</span>