拇指向上/向下Mysql查询

时间:2012-05-11 18:50:45

标签: mysql select

我有两张桌子。

my_comment_thumbs [thumb_member_id, Cmt_id, thumb]
my_Comment [id, page, member_id, comment, ip]

竖起大拇指,thumb='1',以及竖起大拇指,thumb='0'

[不确定这是否非常清楚。]

我一直在努力让每个评论竖起大拇指和大拇指。

到目前为止我已经得到了什么[没有完全理解我所拥有的......]

SELECT 
SUM(IF(thumb='1', 1, 0)) AS t_up, 
SUM(IF(thumb='0', 1, 0)) AS t_down, 
id, member_id, comment, ip 
FROM my_Comment LEFT OUTER JOIN my_comment_thumbs ON member_id=thumb_member_id 
WHERE page='333'

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

表示拇指= 1或拇指= 0;

"SELECT COUNT(*) FROM my_comment_thumbs,my_Comment 
   WHERE   
       my_Comment.id=my_comment_thumbs.Cmt_id 
          AND 
       my_comment_thumbs.thumb=1 
          AND 
       member_id=thumb_member_id;"

答案 1 :(得分:0)

由于我没有数据设置,我可以测试一下,我认为这样可行 - 但它没有经过测试:

SELECT 
    (SELECT count(thumb) FROM my_comment_thumbs WHERE thumb=1) as t_up, 
    (SELECT count(thumb) FROM my_comment_thumbs WHERE thumb=0) as t_down, 
    id, member_id, comment, ip 
FROM my_Comment 
LEFT OUTER JOIN my_comment_thumbs ON member_id=thumb_member_id 
WHERE page='333'

希望有所帮助。