Repository navigation
Expand file tree
/
Copy pathQueries_G00375722.sql
More file actions
143 lines (93 loc) · 3.11 KB
/
Copy pathQueries_G00375722.sql
File metadata and controls
143 lines (93 loc) · 3.11 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- select all the patients in the system
SELECT * FROM PATIENT;
-- ***********************************************************************************************
-- find all patients for one postcode
SELECT * FROM patient where eircode = "P24A123";
-- ***********************************************************************************************
-- calculate overdue days for each open bill
SELECT
DATEDIFF(CURRENT_DATE, a.date) AS 'Result',
p.name
FROM
appointments AS a,
patient AS p,
bill AS b
WHERE
b.bill_status = "open" AND b.patient_ID = a.patient_ID AND b.patient_ID = p.patient_ID;
-- **********************************************************************************
-- display number of patients who have outstanding bills
SELECT
COUNT(`patient_ID`)
FROM
patient
WHERE
`outstanding_balance` > 0;
-- *******************************************************************************
-- display bill item information for patient Mary Murphy id = 1
SELECT
bi.bill_ID,
tg.description,
tg.price
FROM
patient_chart_details AS pcd,
bill_items AS bi,
treatment_guide AS tg
WHERE
pcd.patient_ID = 3 AND pcd.chart_item_ID = bi.chart_item_ID AND pcd.treatment_ID = tg.treatment_ID;
-- ************************************************************************************************
-- select treatment history for patient with id=3 (Tim Collins) given by MulCahy dentists.
SELECT
t.description
FROM
patient_chart_details AS pcd,
treatment_guide AS t
WHERE
pcd.patient_ID = "3" AND pcd.treatment_ID = t.treatment_ID AND pcd.treatment_status = "work done";
-- **********************************************************************************************
-- show complete history for a patient with id 5 – local treatments and any specialist treatments
SELECT
t.description AS "Treatment(s)",
a.date AS "Date"
FROM
patient_chart_details AS pcd,
treatment_guide AS t,
appointments AS a
WHERE
pcd.patient_ID = "5" AND pcd.treatment_ID = t.treatment_ID AND pcd.treatment_status = "work done" AND pcd.appointment_ID = a.appointment_ID
UNION ALL
SELECT
pst.treatment_desc,
pst.treatment_received
FROM
patient_specialist_treatments AS pst
WHERE
pst.patient_ID = "5";
-- **************************************************************************************
-- change a phone number
UPDATE
`patient_phone_number`
SET
`phone_no` = '087 5666975'
WHERE
`patient_phone_number`.`eircode` = 'P24D123' AND `patient_phone_number`.`phone_no` = '087 5778975';
-- **************************************************************************************************
-- add a new treatment offering to the existing list
INSERT INTO `treatment_guide`(
`treatment_ID`,
`description`,
`price`,
`treatment_duration`
)
VALUES(
'3232',
'Top Up whitening gel syringe',
'30',
'30'
);
-- ****************************************************************************************
-- delete a treatment with id 3232
DELETE
FROM
treatment_guide
WHERE
treatment_ID = 3232;