This statement is used to embed a subquery in the HAVING clause. The subquery result is used as a part of the HAVING clause.
1 2 3 | SELECT [ALL | DISTINCT] attr_expr_list FROM table_reference GROUP BY groupby_expression HAVING aggregate_func(col_name) operator (sub_query); |
To group the student_info table according to the name field, count the records of each group, and return the number of records in which the name fields in the student_info table equal to the name fields in the course_info table if the two tables have the same number of records, run the following statement:
1 2 3 | SELECT name FROM student_info GROUP BY name HAVING count(name) = (SELECT count(*) FROM course_info); |