我在使用下面的脚本时遇到了这个错误,我在这个网站和谷歌上搜索了很多线程,但我找不到我的问题的解决方案。
select ct.tons as total_tons,
sum(IF(sum(wr.tons) is not null,sum(wr.tons),0)) as total_delivered,
sum(ct.tons - IF(sum(wr.tons) is not null,sum(wr.tons),0)) as total_balance,
sum(IF(sum(f.tons_fixed) is not null, sum(f.tons_fixed), 0)) as total_fixed,
sum(IF(sum(f.tons_fixed) is not null, ct.tons - sum(f.tons_fixed), 0)) as total_unfixed,
avg(sum(IF(f.tons_fixed * f.hedge_price is not null,f.tons_fixed * f.hedge_price, 0))/IF(sum(f.tons_fixed) is not null, sum(f.tons_fixed), 1) + ct.differential_fob) as avg_contract_price,
avg(db.current_basis) as avg_market_price,
avg(ct.contract_price_foreign - db.current_basis) as avg_outright_fob,
avg(ct.differential_fob) as avg_contract_fob_diff,
avg(IF(mf.diff is not null, mf.diff, 0)) as avg_market_fob,
avg(ct.differential_fob - IF(mf.diff is not null, mf.diff, 0)) as avg_diff_fob
from contract ct
left join grade_master gm on ct.grade_id = gm.id
left join movement m on m.contract_id = ct.id
left join warehouse_receipt wr on wr.movement_id = m.id
left join daily_basis db on ct.terminal_month = db.id
left join contract_price_fixation f on f.contract_id = ct.id
left join market_fob_diff mf on mf.grade_id = ct.grade_id
left join grade_master gmt on mf.grade_id = gmt.id
left join company_master cm on cm.id = ct.supplier_buyer_id
GROUP BY ct.id
我认为问题可能是总和(平均)内的总和,因为在删除最左边的总和时,脚本有效。请帮我纠正它!
谢谢