In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "sql how to find duplicate data", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "sql how to find duplicate data" bar!
Write a SQL query to find all duplicate student names in the student table.
[problem-solving ideas]
1. To see the keyword "find repetition", first use the grouping function (group by), and then count the name column with the count function count () in the aggregate function.
two。 After grouping and summarizing, a table is generated as follows. Selecting a name with a count greater than 1 from this table is a duplicate name.
[problem solving steps]
Method one
1) create an auxiliary table to summarize the columns of last names in row groups
Select name, count (name) as count
From student table
Group by name
2) Select the names with a count greater than 1 in the auxiliary table
Select name from Auxiliary form
Where count > 1
3) combine the first two steps, put the step of "creating auxiliary table" into the subquery
Select name from
(
Select name, count (name) as count
From student table
Group by name
) as Auxiliary Table
Where count > 1
Method two
At this time, some students may wonder, why bother to create a subquery, can't you use this statement (put count in the where sentence) to get the answer directly?
Select name
From student table
Group by name
Where count (name) > 1
If we run this sql statement, we will report the following error. What is the problem?
The aggregate function (count) was mentioned earlier, and the where sentence cannot be used with the aggregate function. Because the where clause is in the second running order, the table has not been grouped when it comes to where.
If you want to filter the results of a grouped query, you can use the having clause. Therefore, the best way to solve this problem is as follows:
Select name
From student table
Group by name
Having count (name) > 1
Thank you for your reading, the above is the content of "how to find duplicate data in sql". After the study of this article, I believe you have a deeper understanding of how to find duplicate data in sql, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.