What is the difference between where and having?
Where is a filter before group by, and having a filter for statistics after group by, the general having is used together with group by, combined with aggregate functions, filtered after statistics.
Example:
Table Student (Id,name)
Requirements: Write SQL to isolate the name field from the student table by repeating more than 3 records, and write SQL to delete these duplicate records
First, repeat more than three records:
Select name from student group by name has count (name) >3
Then delete these duplicate records, leaving only one
SELECT * from student where name in (select name from student group by name has COUNT (*) >3)
and ID not in (the Select min (id) from student group by name has COUNT (*) >3)
Analysis: Name is in duplicate records, but ID is not the minimum ID for these duplicate records
It is easy to resolve the data in full repetition, using the DISTINCT keyword, you can get a result set with no duplicates:
SELECT DISTINCT * from TableName
Order of Use: Where.....group By....having.....order by
The use of having in SQL