因此,正如您在标题中看到的那样,我正在寻找如何查找所有tweet赞,然后在不丢失喜欢总结果的情况下向该查询添加喜欢的用户。
这是我的喜欢表。
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 | | +----------+---------+------+-----+---------+----------------+
运行此查询时,我可以得到所有赞:
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 | +-----------+----+----------+-----------+------------+----------------------------------------------------------------------------------------------------------------------------------------------+--------+---------------------+
谢谢
答案 0 :(得分:0)
尝试一下:
SELECT COUNT(*), GROUP_CONCAT(likes.[id_user])
from likes INNER JOIN tweets ON likes.id_tweet = tweets.id
GROUP BY likes.id_tweet;