How many times SQL queries for duplicate values, and what to do with them

Source: Internet
Author: User
Number of times SQL queries duplicate values
A table mark

ID Name pay
1 Sheets 31,000
2 Wang Lei 1200
3 Sheets 35,853
4 Wang 58,574
5 Tall 1259
6 Tall 985

===================
How to query the Name field duplicate values, do not know how to write SQL, the result is that Zhang San appeared several times, Wang Lei appeared several times, Tall appeared several times.


In addition, I do not understand the group by this usage and meaning, who can be popular point of view to tell me, thank you.
------Solution--------------------
Select Name, COUNT (*) from Mark GROUNP by name

GROUP BY group Key
is based on who is grouping
------Solution--------------------
The group BY syntax can group the results of a query based on each member of a given data column, resulting in a grouped summary table.
The column name in the SELECT clause must be a grouping column or a column function. The column function returns a result for each group defined by the GROUP BY clause.
The structure and data of an employee information table are as follows:
ID Name Dept Salary edlevel HireDate
1 Zhang Three Development Department 2000 3 2009-10-11
2 Li Si Development Department 2500 3 2009-10-01
3 Harry Design Department 2600 5 2010-10-02
4 Wangliuqi Design Department 2300 4 2010-10-03
5 MA Seven Design Department 2100 4 2010-10-06
6 Zhao Eight Sales Department 3000 5 2010-10-05
7 Money Nine Sales Department 3100 7 2010-10-07
8 Sun 10 Sales Department 3500 7 2010-10-06
For example, I want to list the results of the highest salary for each department, and the SQL statements are as follows:
SELECT DEPT, MAX (SALARY) as MAXIMUM
From staff
GROUP by DEPT
The query results are as follows:
DEPT MAXIMUM
Development Department 2500
Design Department 2600
Sales Department 3500
Explain the result:
1. The column name in the SELECT clause must be a grouping column or column function, because select has the column dept contained in the GROUP by Dept.
2. The column function returns one result per group defined by the GROUP BY clause, and returns a result for each department according to the Department group, which is the highest salary for each department.
Note: The calculation is for each department (the group defined by the groups by clause) instead of the entire company's MAX (SALARY).

------Solution--------------------
Sum, Max are mathematical functions, and your dis column is character type, and of course it's going to be an error.
Group BY is the meaning of grouping
Group BY is grouped by the contents of the specified column
No GROUP BY is a set of all records
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.