rules repository

G-3183

🆓
Warning

Always specify column aliases instead of expressions in GROUP BY clauses.

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

Non-Compliant Example

select lower(job_id) as job
      ,sum(salary) as sum_salary
  from employees
 group by lower(job_id)
 order by job;
Issues
LineColumnMessage
411Use column alias instead of expression in GROUP BY clause.

Compliant Solution - ★★★★★

select lower(job_id) as job
      ,sum(salary) as sum_salary
  from employees
 group by job
 order by job;

References