gpt4 book ai didi

mysql - 如何获取SQL中每条记录的AVG

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

例如,我需要获取 SQL 中每一行的 AVG:

这是第一个表

+ ---+------+-------------+| course_id | course_name | + ----------+-------------+| 1         | a           || 2         | b           | | 3         | c           | | 4         | g           | + ---+------+-------------+

This is the second table I need to get AVG for both id 1 and 2. the result for example:

+ -------------------+------+----------+| course_feedback_id | rate |course_id |+ -================--+------+----------+|       1            | 4    |   1      ||       2            | 3    |   1      ||       3            | 2    |   2      |+ -------------------+------+----------+

this is the final answer that i need

+ ----------------------+| course_id | AVG(rate) |+ -=======--+-----------+|     1     | 3.5       |   |     2     | 2         |   + ----------------------+

I tried this soulution but it will give me only the first row not all records.

SELECT *, AVG(`rate`) from secondTable 

请帮忙

最佳答案

SELECT `id`, AVG(`rate`) FROM `your_table` GROUP BY `id`

关于mysql - 如何获取SQL中每条记录的AVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53485905/

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