在MySQL的另一个表中插入列中的数据
我有一个名为反馈
的表,其中包含列Mechemail
(forefer键)和rate
。
我有另一个名为机械
的表<代码>电子邮件(主键)和avgrate
。
我想将平均速率从反馈
表插入机械
表中Mechemail
匹配email> email
。
这是我使用的代码,但仅选择 - 但不插入:
SELECT
mechanical.email,
COALESCE(AVG(feedback.rate), 0) AS rate
FROM
mechanical
LEFT JOIN
feedback ON feedback.mechEmail = mechanical.email
GROUP BY
mechanical.email;
I have a table named feedback
which has columns mechEmail
(foreign key) and rate
in it.
I have another table named mechanical
which has columns email
(primary key) and avgrate
.
I want to insert the average rate from the feedback
table into the mechanical
table where mechEmail
matches email
.
Here's the code that I used, but it only selects - but does not insert:
SELECT
mechanical.email,
COALESCE(AVG(feedback.rate), 0) AS rate
FROM
mechanical
LEFT JOIN
feedback ON feedback.mechEmail = mechanical.email
GROUP BY
mechanical.email;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您不需要插入语句,而是一个更新语句,因为您已经在机械表中有电子邮件 -
It seems you don't want an Insert statement but an UPDATE statement as you already have email in mechanical table -