我有 n 个具有不同 articleId 的用户。
如果我传递 articleId,我想获得结果,例如有多少不同的用户查看了该文章。
表
1:
recId userId articleId
----- ------ --------
100 1001 1
103 178 2
106 475 3
107 327 4
108 567 5
109 568 6
表
2:
userId jobtitle articleId
----- ------ --------
327 Engineer 4
178 Professor 4
475 Doctors 4
327 Engineer 5
568 Student 6
475 Doctors 4
475 Doctors 8
如果我将 articleId 作为 4 传递,它应该返回详细信息,例如不同用户查看特定文章的次数,例如:
jobtitle total
----- ------
Doctors 2
Engineer 1
Professor 1
如果我将 articleid 作为 6 传递,结果将是这样的:
jobtitle total
----- ------
Student 1
这个mysql脚本怎么写?
最佳答案
select jobtitle, count(articleid)
from table2
where articleid = YOUR_ARTICLE_ID
group by jobtitle
关于sql - 需要mySql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1967100/