N
N
Nikolai Kokoulin2018-05-10 02:38:34
SQL
Nikolai Kokoulin, 2018-05-10 02:38:34

How to write a SQL query to select unique values ​​for two columns?

there is a table
id uid name params
1 | 333 | Nicholas | a variety of options
2 | 333 | Nicholas | a variety of options
3 | 333 | Igor | a variety of options
4 | 444 | Nicholas | a variety of options
5 | 444 | Anton | a variety of options
6 | 555 | Nicholas | a variety of options
7 | 555 | Anton | a variety of options
8 | 555 | Vasya | a variety of options
9 | 666 | Vasya | a variety of
task options:
get
the name | total meets | How many users have
Nikolai occurs 4 times in 3 users
Anton Occurs 2 times in 2 users
Vasya Occurs 2 times in 2 users
Igor Occurs 1 time in 1 user
how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Kokoulin, 2018-05-10
@Kokoulin

Like this

SELECT 
name, 
count(DISTINCT uid) AS user_count,
count(name) AS vsego
FROM table
GROUP BY name
ORDER BY user_count DESC;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question