philippe philippe - 7 months ago 22
SQL Question

Error message using "group BY" function

I'm trying to use

GROUP BY
using Oracle SQL but I'm getting consistently the following error message (in french):

"ORA-00979: n'est pas une expression GROUP BY
00979. 00000 - "not a GROUP BY expression"


Here is the query i'm using, anyone know what i'm doing wrong?:

select id_ws, duration, phases
from from v_cdco_worksite
left join osi_phases
on v_cdco_worksite.id_ws=osi_phases.id_ws
group by v_cdco_worksite.id_ws;

Answer

Try the following:

select v_cdco_worksite.id_ws, sum(duration) SumDuration, sum (phases) SumPhases
from v_cdco_worksite
left join osi_phases on v_cdco_worksite.id_ws=osi_phases.id_ws
group by v_cdco_worksite.id_ws;

Since id_ws is in both tables you need to specify WHICH one you want and of course WHICH one to group by. Furthermore you forgot to either put the duration into the group by as well or to sum ist up as you did with phases. Hope this helps.

Comments