-5

I have table looks like following

Email                Domain
------               ------
test@gmail.com       gmail.com
test@gmail.com       gmail.com
test@gmail.com       gmail.com
test@yahoo.com       yahoo.com
test@yahoo.com       yahoo.com
test@outlook.com     outlook.com

How do I write a sql query to get the following result

Expected result
---------------
gmail.com    3
yahoo.com    2
outlook.com  1

Any answer will be appreciated. Thanks.

Barmar
  • 741,623
  • 53
  • 500
  • 612

2 Answers2

1

This is the simplest use of GROUP BY

   SELECT domain, COUNT(*)
     FROM mytable
 GROUP BY domain
Jordi Llull
  • 810
  • 6
  • 17
0

Use Group by and Count(*) function, Try this

select Domain,count(*) from Table_Name group by Domain
Karthikeyan
  • 381
  • 8
  • 19