forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
28 lines
2.0 KiB
HTML
28 lines
2.0 KiB
HTML
<a name="EN-US_TOPIC_0000001772696228"></a><a name="EN-US_TOPIC_0000001772696228"></a>
|
|
|
|
<h1 class="topictitle1">GROUP BY Conversion</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_p13755101311585">During MySQL/ADB group query, non-group columns can be queried. During GaussDB(DWS) group query, only group columns and aggregate functions can be queried, and if non-group columns are queried, an error will be reported. Therefore, GROUP BY in GaussDB(DWS) is changed to allow querying on non-group columns.</p>
|
|
<p id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_p2755131310587"><strong id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_b9271136761">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_screen249911610616">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;</pre>
|
|
<p id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_p1755013185819"><strong id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_b175848401566">Output</strong></p>
|
|
<p id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_p97551813185819"></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001772696228__en-us_topic_0000001706105109_en-us_topic_0000001442160981_screen542018441166">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;</pre>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_16_0178.html">SELECT</a></div>
|
|
</div>
|
|
</div>
|
|
|