Reputation: 90
i have one table:
id | name |
-----------
1 | AAA |
2 | BBB |
3 | AAA |
4 | DDD |
5 | BBB |
6 | CCC |
7 | AAA |
8 | BBB |
9 | DDD |
I want to count the that how many times AAA
,BBB
and so on are there.
By using count(*) i am getting the hole count not for single element.
I want the count of all the elements.
like this:
Name | Count
------------
AAA | 3
BBB | 3
CCC | 1
DDD | 2
Not in new table i want it as output.
Upvotes: 3
Views: 653
Reputation: 245
SELECT name AS Name,
count(name) AS Count
FROM Table
GROUP BY name ASC;
Upvotes: 0
Reputation: 11
Here is the simplest way to count rows with what you want to match:
sql> select count(*) as count from table_name where name like 'AAA';
Upvotes: 0
Reputation: 263723
Use COUNT()
aggregate function to get the total number of records for each NAME
.
SELECT name, COUNT(*) totalCOUNT
FROM tableName
GROUP BY name
Upvotes: 5