У меня есть 3 таблицы:
users
id device
11 SM-G955F
12 iPhone8,2
13 SM-G955F
14 LG-H812
15 SM-G955F
16 SM-G955F
17 iPhone8,2
2
activity
user_id login_time
11 2018-05-11
12 2018-05-11
13 2018-05-11
14 2018-05-12
14 2018-05-14
15 2018-05-14
11 2018-05-14
12 2018-05-14
3
payments
user_id
15
17
11
Какой запрос мне нужно сделать, чтобы рейтинг топ-3 устройств 14.05.2018 соответствовал числу пользователей по активности?
Нужно три столбца:
device number_of_users number_of_users
(from activity) (from payments if there were)
Это мой запрос:
select u.device, count(distinct u.id) as number_of_users from users u inner
join activity a on a.user_id = u.id where a.login_time = '2018-04-18' group
by u.device order by number_of_users DESC limit 3;
Но я не могу отображать пользователей из платежей