gpt4 book ai didi

Mysql:如何获取评分数据

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

我想获取每个提要及其相应的 rating 。我有这个mysql查询

    SELECT
user_feed.*, COALESCE(SUM(feed_rating.rating), 0) AS rating
FROM
user_feed
LEFT JOIN
feed_rating
ON
feed_rating.feed_id = user_feed.id

但它只返回一行,而实际上我有 2 user_feeds 。如果我删除聚合函数 sum,它会返回两个 user_feed。

最佳答案

group bySUM结合使用

group by feed_id

尝试这个查询

 SELECT
user_feed.*, COALESCE(SUM(feed_rating.rating), 0) AS rating
FROM
user_feed
LEFT JOIN
feed_rating
ON
feed_rating.feed_id = user_feed.id group by feed_id

aggregate function performs a calculation on a set of values and returns a single value

关于Mysql:如何获取评分数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33492290/

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