我有一个 MySQL 查询,它运行了一个简单的操作(对选择语句中的计数进行求和),我想使用结果进行数学运算,但是出现错误。
表格:
id | group | count |
-----------------------------
1 1 3
2 1 2
查询:
select id, count,
(select sum(count) from table group by group) as total,
count/total as percent
from table
这个错误是由于表中没有真实的“总计”列所引起的。我该如何使查询正常工作?
ERROR 1054 (42S22): Unknown column 'total' in 'field list'
。 - MechEngineer