数据仓库服务 GAUSSDB(DWS)-GROUP BY转换

时间:2024-11-15 15:20:01

GROUP BY转换

MySQL/ADB分组查询的时候允许查询非分组字段,不报错;DWS分组查询时只能查询分组字段和聚集函数,报错。因此补齐没有group by的查询分组字段。

输入示例

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;

输出示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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,
  1
ORDER BY
  department_name;
support.huaweicloud.com/tg-dws/dws_16_0182.html