您好,我有一个SQL查询选择第一列中的SUM值,我希望第二列为(first_column / another_field)
select sum(a.amount), (sum(a.amount) / d.total_loading_weight * 1000) as MarginPerTon
from tra_affair a join tra_Delivery d on a.delivery=d.delivery_id
where a.delivery='394179' and a.is_margin='1'
我收到“不是单组分组功能”错误
答案 0 :(得分:1)
问题是:d.total_loading_weight
。我不确定您想要什么,但是类似:
select sum(a.amount),
(sum(a.amount) / sum(d.total_loading_weight * 1000)) as MarginPerTon
from tra_affair a join
tra_Delivery d
on a.delivery = d.delivery_id
where a.delivery = '394179' and a.is_margin = '1';
如果值始终相同,也可以使用min()
或max()
代替sum()
。