我有用户列表和访问表。我想要一个已查看其个人资料的用户列表:

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' ║
╚═════════════════╝


我想要每个用户的观看次数

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

最佳答案

您似乎想要count(distinct)

select visited, count(distinct visitor)
from t
group by visited;

10-08 18:47