Skip to content
Advertisement

Group by in one table

I have list of users and a visits table . I want a list of users whose profile has been viewed :

visits table
╔═════════════════╗
║ vistor  visited ║
╠═════════════════╣
║'26000', '26023' ║
║'26000', '26023' ║
║'26000', '26023' ║
║'26000', '26023' ║
║'26000', '26023' ║
║'26000', '26023' ║
║'26000', '26023  ║
║'26001', '26023' ║
║'26001', '26023' ║
║'26002', '26023' ║
║'26005', '26000  ║
║'26005', '26000' ║
║'26004', '26000' ║
╚═════════════════╝

I want number of views per user

╔═════════════════╗
║ visited  count  ║
╠═════════════════╣
║'26023',  3      ║
║'26000',  2      ║
╚═════════════════╝

Advertisement

Answer

You seem to want count(distinct):

select visited, count(distinct visitor)
from t
group by visited;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement