I have got a table with several visits of patients to several doctors, and each visit has got its own note
column, for a staff member to insert notes from the visit.
Each visit has got a column for each Note from the visit, made by a staff member. e.g. Note_visit1
, Note_visit2
, Note_visit3
.
Each visit has also got a record of the staff's ID e.g. StaffID_visit1
, StaffID_visit2
, StaffID_visit3
.
My problem is trying to answer this question:
The number of notes made by each staff member on each patient.
The table looks something like this, ignore the dumb notes.
patientID| Note_V1 | StaffID_v1 | Note_V2 | StaffID_v2 |
1 | "cat" | 101 | "dog" | 102 |
2 | "camel" | 105 | "rat" | 101 |
PatientVisit
: columnsPatientID
,StaffID
,Note
, (Date/Time,)... You might decide you want aVisitID
column too, which might be an auto-allocated increasing number (sequence, ...). Then your query is essentially trivial. You also don't run into problems with someone who visits 70 times not having enough space for all their visits, and all sorts of other goodies. If you have 3 visits in a single row, you have to write each condition out 3 times — and worry about whether nulls screw things up when only the visit 1 columns hold data.