开发者

Need mySql query

I have n number of users with different articleId.

If I pass the articleId, I want to get the results like how many different users viewed that article.

Table 1:

recId   userId   articleId    
-----   ------    --------
100      1001      1   
103      178       开发者_开发问答2   
106      475       3   
107      327       4   
108      567       5   
109      568       6   

Table 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

If I pass the articleId as 4, It should return the details like how many times that particular article viewed by different users like:

jobtitle   total
-----      ------    
Doctors     2
Engineer    1
Professor   1

if i pass articleid as 6, result will be like this:

jobtitle   total
-----      ------    
Student      1

How to write this mysql script?


select jobtitle, count(articleid)
from table2 
where articleid = YOUR_ARTICLE_ID
group by jobtitle


SELECT jobtitle, COUNT(*) as count
FROM Table2
WHERE articleId = 4
GROUP BY jobtitle
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜