We may group by table columns that are not in the SELECT list, like GRP_B in the example below.
select grp_a, count(*) from t group by grp_a, GRP_B order by grp_a, grp_b ;
GRP_A COUNT(*) ------ ---------- a1 2 a1 3 a2 3
However we may not select table columns that are absent from the GROUP BY list, as with GRP_A in this example.
select GRP_A, count(*)
from t
GROUP BY GRP_B ;
select GRP_A, count(*)
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
