I have created a VIEW (VISIT_VIEW) that has two columns, citizens and count(visitsDoctors) AS ToTal_Visits:
CREATE VIEW VISIT_VIEW AS
SELECT citizen, COUNT(doctor) AS Total_Visits
FROM citizensvisits
GROUP BY citizen, doctor;
That returns a lis of how many times each citizen has visited a doctor
citizen1 1
citizen1 2
citizen1 5
...
citizen3 10
citizen3 4
Then I need to create a new view that will hold the MAX of the TotalVisits and for each citizen
CREATE VIEW MAXVISITS AS
SELECT citizens, Total_Visits AS MaxTotal_Visits
FROM VISIT_VIEW
WHERE MaxTotal_Visits = max("Total_Visits")
GROUP BY citizens, MaxTotal_Visits;
so when trying to
SELECT *
FROM MAXVISIT_VIEW
I get
Result: misuse of aggregate: max()
What am I doing wrong ?
edit: I ve put the VISIT_VEW code and to clarify, I need a new view that should list for each citizen's its MAX visits ie
citizen1 5
citizen3 10