gpt4 book ai didi

MySQL:简单查询修改

转载 作者:行者123 更新时间:2023-11-29 05:30:38 25 4
gpt4 key购买 nike

有这三个表:

  1. 帖子
  2. posts_replies
  3. 喜欢

此查询返回我的帖子,他们的回复都算正常。

SELECT posts.title, posts.num, posts.status, posts.category, posts.content, posts.member_num, COUNT( posts_replies.blyrb_num ) AS count, COUNT( likes.comment_num ) AS likes_count
FROM posts_replies
INNER JOIN posts ON ( posts_replies.blyrb_num = posts.num )
LEFT JOIN likes ON ( likes.comment_num = posts_replies.num )
WHERE posts.status <>3
AND posts.access = 'Public'
AND (
posts.title LIKE '%dress%'
OR posts.content LIKE '%dress%'
)
GROUP BY posts.num

但问题是这个查询只返回有一些回复的帖子。我不想要这样的限制,我想要所有的帖子,不管他们有没有回复。

关于我在这里做错了什么有什么想法吗?

谢谢

最佳答案

交换“FROM”和您的第一个“JOIN”中的表,并将您的第一个“JOIN”更改为 LEFT JOIN,应该可以解决问题:

SELECT posts.title, posts.num, posts.status, posts.category, posts.content, posts.member_num, COUNT( posts_replies.blyrb_num ) AS count, COUNT( likes.comment_num ) AS likes_count
FROM posts
LEFT JOIN posts_replies ON ( posts_replies.blyrb_num = posts.num )
LEFT JOIN likes ON ( likes.comment_num = posts_replies.num )
WHERE posts.status <>3
AND posts.access = 'Public'
AND (
posts.title LIKE '%dress%'
OR posts.content LIKE '%dress%'
)
GROUP BY posts.num

关于MySQL:简单查询修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15184033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com