select sum(raw_ore) raw_ore ,(select sum(raw_ore0) from trv_daily where p_year=a.p_year ) lift_ore from trv_refine a where p_year=2024
儘管語句select sum(raw_ore0) from trv_daily where p_year=a.p_year ,只返回一個數值,系統提示“ORA-00937:不是單分組函式”
將子查詢外面新增max等統計函式,即可解決該問題。
select sum(raw_ore) raw_ore ,max((select sum(raw_ore0) from trv_daily where p_year=a.p_year )) lift_ore from trv_refine a where p_year=2024
總結:在分組查詢中,只允許2類列,分組依據列(group by)和分組查詢列(sum、count)等。