Updated on 2025-10-14 GMT+08:00

GROUP BY Conversion

In GROUP BY statements, non-group columns can be queried in MySQL and ADB, but only group columns and aggregate functions can be queried in DWS. To query non-group columns, you need to use the MySQL compatibility mode with disable_full_group_by_mysql enabled.

Input

1
SELECT e.department_id, department_name, ROUND(AVG(salary), 0) avg_salary FROM employees e JOIN departments d on e.department_id = d.department_id GROUP BY department_name ORDER BY department_name;

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT
  e.department_id,
  department_name,
  ROUND (AVG(salary), 0) AS "avg_salary"
FROM
  employees "e"
  JOIN departments "d" ON e.department_id = d.department_id
GROUP BY
  department_name
ORDER BY
  department_name;