D
D
dylan552021-09-22 08:05:24
PostgreSQL
dylan55, 2021-09-22 08:05:24

How to separate a mail domain and group it?

id | name | email 
--------------------------
1 | Вася | [email protected]
2 | Петя | [email protected]
3 | Маша | [email protected]
4 | Игорь | [email protected]
5 | Витя | [email protected]

How to make a request to get:
email | кол-во
--------------------
mail.ru | 2
yandex.ru | 2
gmail.com | 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-09-22
@dylan55

select right(email, -strpos(email, '@')) as domain, count(*)
  from t
 group by 1
 order by 2 desc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question