I need some help on Oracle SQL, appreciate anyone who can advise me on the right query to run.
I have 3 tables as follows:
Patient (**PatientNo**, DocName, ProviderNo, DateRegistered)
PrivateDoctor (**ProviderNo**, **DocName**)
PrivateClinic (**ProviderNo**, Address, TelNo)
Patient: DocName & ProviderNo are foreign keys to PrivateDoctor
PrivateDoctor: ProviderNo is foreign key to PrivateClinic
I need to create a "View" to list all private clinic doctors (including Address, Telephone Number and ProviderNo) who referred Patients to the hospital in last 6 months and the number of patients referred (e.g DateRegistered).
Below is what I tried to run.
SELECT Patient.DocName
, Patient.ProviderNo
, PrivateClinic.Address
, PrivateClinic.TelNo
, Patient.DateRegistered
, count (Patient.PatientNo)
FROM Patient
JOIN PrivateDoctor ON Patient.ProviderNo = PrivateDoctor.ProviderNo
JOIN PrivateClinic ON PrivateDoctor.ProviderNo = PrivateClinic.ProviderNo
WHERE Patient.DateRegistered >= ADD_MONTHS(TRUNC(SYSDATE, 'MONTH'), -5)
AND Patient.DateRegistered < ADD_MONTHS(TRUNC(SYSDATE, 'MONTH'), 1)
Group By Patient.DocName;
Below is the error message.
ORA-00979: not a GROUP BY expression
00979. 000 00 - "not a GROUP BY expression"
*Cause:
*Action:
Error at Line: 1 Column: 39