Grokking SQL for Tech Interviews
Vote

0% completed

HAVING

HAVING

In MySQL, the HAVING clause is used in conjunction with the GROUP BY clause to filter the results of a query based on aggregate functions.

The HAVING clause is applied after the GROUP BY clause and allows you to specify conditions for groups of rows. It is primarily used with aggregate functions like SUM, COUNT, AVG, etc.

Syntax

SELECT column_name FROM table_name WHERE condition GROUP BY column_name HAVING condition

Example

Suppose we have a Students table as shown below:

Now, let's say you want to find courses where the number of students who

.....

.....

.....

Like the course? Get enrolled and start learning!
M

m.malak.fahmy

· 2 years ago

Wrong result value for the mentioned example

Hasnain Zeeshan

Hasnain Zeeshan

· 2 years ago

The answer should not include the 2nd row because there is only 1 English student with a mark over 80