SELECT p.post_id, p.post, count(pl.user_id) as likes
FROM `post` as p
join post_likes as pl on p.post_id = pl.post_id
where 1 group by pl.post_id
having likes >= 10;
SELECT p.post_id, COUNT(l.user_id) AS TotalLikesCount
FROM posts AS p
JOIN likes AS l ON p.post_id = l.post_id
GROUP BY p.post_id
HAVING TotalLikesCount >= 10
6条答案
按热度按时间hmae6n7t1#
在表t2中,出现超过10行的post\u id是所需的post,因此您可以选择表t2中至少有10行出现post\u id的post
8ehkhllq2#
您可以使用join选择文章。
du7egjpx3#
4bbkushb4#
你能用一个副选择器吗?
wn9m85ua5#
您可以将所选内容分组,然后使用
having
```SELECT posts.*, COUNT(likes.id) as likesCount
FROM posts, likes
GROUP BY posts.id HAVING (likesCount >= 10)
gj3fmq9x6#
具有最佳性能和避免“笛卡尔积”使用的目的
join
,如下所示: