SQL: counting common elements

I am trying to find a table that displays the total number of common items in the table.

For instance. I have table A with the values:

colName ============= a b b c c c d 

Is there a way that I can come up with a result that displays:

 colName totalCount ================== a 1 b 2 c 3 d 1 
+4
source share
1 answer

This is a simple query using the aggregate function COUNT and GROUP BY .

 SELECT colName, COUNT(colName) totalCount FROM tableName GROUP BY colName 

totalCount is called ALIAS COUNT(colName)

+4
source

Source: https://habr.com/ru/post/1439649/


All Articles