Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对不起,这个问题有点含糊,让我重新表述我的问题。
表:
所以用户有活动,每个活动都可以有一个标签,例如“阅读邮件”将是一个活动的标签。所以让我们举个例子:
并且用户 mike 有另一个活动:
现在您可以看到用户“mike”有 2 个活动与“阅读电子邮件”,所以当用户创建大量活动时,我需要获取最喜欢(最常用)的标签。
以下 SQL 将返回特定用户使用最多的标签名称(在本例中为 123)
如果您想根据使用频率列出标签,您可以更改limit 1.
limit 1
select tags.name from tags left join items on tags.id=items.tagId where items.userId=123 group by tags.name order by count(items.id) desc limit 1;