-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path047.sql
More file actions
47 lines (39 loc) · 1.3 KB
/
047.sql
File metadata and controls
47 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Q: All patients who have gone through admissions, can see their medical documents on our site. Those patients are given a temporary password after their first admission. Show the patient_id and temp_password.
The password must be the following, in order:
1. patient_id
2. the numerical length of patient's last_name
3. year of patient's birth_date
Table Info: patients
+--------------+----------+
| Column Name | Type |
+--------------+----------+
| patient_id | INT |
| first_name | TEXT |
| last_name | TEXT |
| gender | CHAR(1) |
| birth_date | DATE |
| city | TEXT |
| province_id | CHAR(2) |
| allergies | TEXT |
| height | INT |
| weight | INT |
+--------------+----------+
Table Info: admissions
+----------------------+----------+
| Column Name | Type |
+----------------------+----------+
| patient_id | INT |
| admission_date | DATE |
| discharge_date | DATE |
| diagnosis | TEXT |
| attending_doctor_id | INT |
+----------------------+----------+
*/
-- SOLUTION:
select
p.patient_id,
concat(p.patient_id, length(p.last_name), year(p.birth_date)) as temp_password
from patients p
join admissions a
on p.patient_id = a.patient_id
group by p.patient_id;