我想获得所有超过 250 个赞的帖子(喜欢存储在不同的表格中)
I want to get all posts which has more than 250 likes(likes are stored in different tabe)
我有两个 mysql 数据库 table 的帖子和 post_likes...我想获得所有超过 250 个赞的帖子
现在我正在使用这个查询:-
SELECT posts.*, @total_likes := COUNT(nft_likes.id) as total_likes FROM posts
inner join nft_likes on nft_likes.nft_id=posts.auction_id 其中@total_likes>1 组 posts.id
这是我第一次问question.so不好的讲述方式请见谅
post_likes table schema
post table schema
在 WHERE
子句中,您只能引用一行的数据。但是,COUNT
的结果是指几行的聚合。使用 HAVING
子句限制这些结果。
SELECT
p.*,
COUNT(l.id) AS total_likes
FROM posts p
INNER JOIN nft_likes l ON l.nft_id = p.auction_id
GROUP BY p.id
HAVING COUNT(l.id) > 1
ORDER BY p.id;
我有两个 mysql 数据库 table 的帖子和 post_likes...我想获得所有超过 250 个赞的帖子
现在我正在使用这个查询:-
SELECT posts.*, @total_likes := COUNT(nft_likes.id) as total_likes FROM posts
inner join nft_likes on nft_likes.nft_id=posts.auction_id 其中@total_likes>1 组 posts.id
这是我第一次问question.so不好的讲述方式请见谅
post_likes table schema
post table schema
在 WHERE
子句中,您只能引用一行的数据。但是,COUNT
的结果是指几行的聚合。使用 HAVING
子句限制这些结果。
SELECT
p.*,
COUNT(l.id) AS total_likes
FROM posts p
INNER JOIN nft_likes l ON l.nft_id = p.auction_id
GROUP BY p.id
HAVING COUNT(l.id) > 1
ORDER BY p.id;