(F) .HAVING Clause in SQL
(F) .HAVING Clause in SQL
The HAVING clause was added to SQL because the WHERE keyword
cannot be used with aggregate functions.
Note: that aggregate functions cannot be used in the WHERE clause. Aggregate functions
act on data that has been grouped using the GROUP BY clause, whereas the WHERE
clause filters individual rows before they are grouped.
Creating table
INSERT INTO Employee VALUES (1, 'Rachit', 'M', 50000, 'Engineering', '6 year')
INSERT INTO Employee VALUES (2, 'Shobit', 'M', 37000, 'HR', '3 year')
INSERT INTO Employee VALUES (3, 'Isha', 'F', 56000, 'Sales', '7 year')
INSERT INTO Employee VALUES (4, 'Devi', 'F', 43000, 'Management', '4 year')
INSERT INTO Employee VALUES (5, 'Akhil', 'M', 90000, 'Engineering', '15 year')
The final table is:
Suppose, a teacher wants to announce the toppers in class. For this, she decides to
reward every student who scored more than 95%. We need to group by name and
their percentage and find out who scored more than 95% in that year. So for this
first, we will create a table named “Student” .After creating a table we will execute
the query.
Creating table