Skip to content

G-3183: Always specify column aliases instead of expressions in GROUP BY clauses.

Minor

Maintainability

Restriction

Oracle Database 23c

Reason

Starting with Oracle Database 23c, it is possible to use a column alias in the group by clause instead of repeating the expression used in the select list.

Unless you use rollup, cube or grouping sets, it is not necessary to use expressions in the group by clause.

Example (bad)

1
2
3
4
5
select lower(job_id) as job
      ,sum(salary) as sum_salary
  from employees
 group by lower(job_id)
 order by job;

Example (good)

1
2
3
4
5
select lower(job_id) as job
      ,sum(salary) as sum_salary
  from employees
 group by job
 order by job;