0

我有两张桌子。

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'

任何帮助是极大的赞赏。

4

2 回答 2

0

对于 thumb=1 或 thumb =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;"
于 2012-05-11T19:02:41.717 回答
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'

希望有帮助。

于 2012-05-11T19:11:35.327 回答