skip to Main Content

Well, that is, there are two Johns and one Quill, you need to output the number of those people who have the same name. In one column there should be the total number of students with the same names

SELECT COUNT(id) as count
FROM student
GROUP BY LOWER(first_name) HAVING COUNT(LOWER(first_name)) > 1;

it will output for each name the count, how to make the total?

2

Answers


  1. In order to get the total, select from your query result and add the counts up.

    SELECT SUM(cnt)
    FROM
    (
      SELECT COUNT(*) AS cnt
      FROM student
      GROUP BY LOWER(first_name)
      HAVING COUNT(*) > 1
    ) counts;
    
    Login or Signup to reply.
  2. Please, try the following:

    SELECT SUM(COUNT(id)) as Total
    FROM student
    GROUP BY LOWER(first_name) HAVING COUNT(LOWER(first_name)) > 1;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search