我已经更改了我的线程,因为我的上一个线程也与此相同。但实际上这是我的要求。
我有 n 个具有不同articleId 的用户。 如果我传递articleId,我想获得结果,例如有多少不同的用户查看了该文章。
表1:
recId userId articleId ----- ------ -------- 1 10111 102 2 10121 102 3 10111 102 4 10121 105 5 10111 102 6 10122 105
表2:
userId jobtitle ----- ------ 10111 Engineer 10121 Doctor 10122 Professor
如果我将 Table1 中的articleId 作为“102”传递,它应该返回详细信息,例如不同用户查看特定文章的次数,例如:
jobtitle total ----- ------ Engineer 3 Doctor 1 Professor 1
如果我将articleid传递为“105”,结果将是这样的:
jobtitle total ----- ------ Doctor 1 Professor 1
如何编写上述结果的查询?
提前致谢
- 格纳尼亚尔·祖贝尔
最佳答案
SELECT jobtitle, COUNT(*) AS total
FROM table1
JOIN table2 ON ( table1.userId = table2.userId )
WHERE articleId = <your articleid>
GROUP BY table2.jobtitle
关于mysql - 需要Mysql查询(线程已更改),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1968993/