gpt4 book ai didi

php - 选择用户喜欢的推文中的所有喜欢

转载 作者:行者123 更新时间:2023-11-29 16:24:03 24 4
gpt4 key购买 nike

因此,正如您在标题中所看到的,我正在寻找如何找到所有点赞的推文,然后将点赞的用户添加到此查询中,而不会丢失点赞的总结果。

这是我的喜欢表。

SELECT COUNT(*) 
from likes INNER JOIN tweets ON likes.id_tweet = tweets.id
GROUP BY likes.id_tweet;
+----------+---------+------+-----+---------+----------------+| Field    | Type    | Null | Key | Default | Extra          |+----------+---------+------+-----+---------+----------------+| id       | int(11) | NO   | PRI | NULL    | auto_increment || id_user  | int(11) | NO   | MUL | NULL    |                || id_tweet | int(11) | NO   | MUL | NULL    |                |+----------+---------+------+-----+---------+----------------+

When I run this query, I can get all the likes :

SELECT COUNT(*) 
from likes INNER JOIN tweets ON likes.id_tweet = tweets.id
GROUP BY likes.id_tweet;

像这样:

+----------+| COUNT(*) |+----------+|        1 ||        4 ||        1 ||        1 ||        2 ||        1 ||        1 ||        1 ||        1 ||        2 ||        1 ||        1 ||        3 ||        1 ||        1 ||        1 ||        1 ||        1 ||        1 ||        1 ||        3 ||        2 ||        1 ||        1 ||        2 ||        1 ||        3 ||        1 ||        1 ||        1 ||        3 ||        3 ||        2 |+----------+

我得到了所有的喜欢,但是当我添加

 where likes.id_users = ... 
我只为一个用户点赞而失去了所有点赞,具体来说,我想恢复用户点赞的所有推文的点赞。

像这样

+-----------+----+----------+-----------+------------+----------------------------------------------------------------------------------------------------------------------------------------------+--------+---------------------+| all likes | id | id_reply | id_poster | id_retweet | text                                                                                                                                         | id_img | tweet_date          |+-----------+----+----------+-----------+------------+----------------------------------------------------------------------------------------------------------------------------------------------+--------+---------------------+|         50 |  2 |     NULL |      1714 |       NULL | Mon premier tweet                                                                                                                            |   NULL | 2019-01-23 14:25:24 ||         43 | 35 |     NULL |      1752 |       NULL | Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl. Aenean lectus. P |   NULL | 2018-04-29 00:00:00 ||         22 | 50 |     NULL |      1908 |       NULL | In congue. Etiam justo. Etiam pretium iaculis justo. In hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus.                |   NULL | 2018-05-23 00:00:00 |+-----------+----+----------+-----------+------------+----------------------------------------------------------------------------------------------------------------------------------------------+--------+---------------------+

谢谢

最佳答案

试试这个:

SELECT COUNT(*), GROUP_CONCAT(likes.[id_user])
from likes INNER JOIN tweets ON likes.id_tweet = tweets.id
GROUP BY likes.id_tweet;

关于php - 选择用户喜欢的推文中的所有喜欢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54360729/

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