So basically my issue is I have the following query and I'm getting an error saying there's a syntax error but I can work out what. I'm wondering whether I can't using HAVING COUNT() in a subquery.
SELECT FIELDNUM
FROM INTEREST
GROUP BY FIELDNUM
HAVING COUNT(ACNUM) >= ALL(SELECT FIELDNUM
FROM INTEREST
HAVING COUNT(ACNUM));
The syntax error shows up at the last 2 closing parenthesis, ie HAVING COUNT( ACNUM )) ;
The outcome I am trying to get is the field (FIELDNUM) with the most academics(ACNUMS) interested in it but I'm not allowed to use MAX or ROWNUM.
The interest table has the attributes FIELDNUM, ACNUM, and DESCRIPTION.
The query would at least make sense if it were structured as:
SELECT FIELDNUM
FROM INTEREST
GROUP BY FIELDNUM
HAVING COUNT(ACNUM) >= ALL (SELECT COUNT(ACNUM)
FROM INTEREST
GROUP BY FIELDNUM
);
This is not how I would recommend writing the logic to get the fieldnum
s that occur the most times in the table, but it is a valid method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.