如何解决如何计算博客的总评论和反应
我有三个表 blogs,blog_comments 和 blogs_reacts(存储用户对博客的喜欢、喜爱和感谢反应)
我想列出所有博客及其评论和反应总数,
我试过这个 sql 语句,但计数错误:
SELECT b.blog_id,title,description,count(blog_comments_id),COUNT(blog_react_id)
FROM blog_comments
RIGHT JOIN blogs b on blog_comments.blog_id = b.blog_id
LEFT JOIN blogs_reacts br on b.blog_id = br.blog_id
GROUP BY b.blog_id
表格说明如下: 博客表
DESC blogs;
Field Type Null Key Default Extra
blog_id bigint(20) unsigned NO PRI auto_increment
content_type varchar(20) NO
title varchar(128) NO
description text YES
image varchar(255) YES
user_id bigint(20) unsigned NO MUL
created_at timestamp NO CURRENT_TIMESTAMP
updated_at timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
blog_comments 表:
DESC blog_comments;
Field Type Null Key Default Extra
blog_comments_id bigint(20) unsigned NO PRI auto_increment
comment_text text NO
user_id bigint(20) unsigned NO
blog_id bigint(20) unsigned NO
created_at timestamp YES CURRENT_TIMESTAMP
updated_at timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
blogs_reacts 表
DESC blogs_reacts;
Field Type Null Key Default Extra
blog_react_id bigint(20) unsigned NO PRI auto_increment
blog_id bigint(20) unsigned NO MUL
user_id bigint(20) unsigned NO
react_type_id int(11) NO
created_at timestamp NO CURRENT_TIMESTAMP
updated_at timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
请帮帮我
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。