MYSQL 中的 SUM(子查询)

2022-01-23 00:00:00 subquery aggregation mysql

基本上,我正在尝试以下方法:

Basically, I am trying the following:

SELECT m.col1, SUM(SELECT col5 FROM table WHERE col2 = m.col1)
FROM table AS m

这似乎不起作用.有什么解决办法吗?

This doesn't seem to work. Is there any solution?

推荐答案

你为什么不这样做:

SELECT m.col1, (SELECT SUM(col5) FROM table WHERE col2 = m.col1)
FROM table AS m

相关文章