oracle中g(shù)roupby的用法是什么

小億
148
2024-03-28 17:59:59
欄目: 云計(jì)算

在Oracle中,GROUP BY用于將查詢的結(jié)果集按照一列或多列進(jìn)行分組,并對(duì)每個(gè)組應(yīng)用聚合函數(shù)(如SUM、AVG、COUNT等)進(jìn)行計(jì)算。GROUP BY子句必須緊跟在SELECT子句之后,并在WHERE子句之前。

示例:

SELECT department_id, SUM(salary)
FROM employees
GROUP BY department_id;

上述示例中,首先按department_id列對(duì)employees表進(jìn)行分組,然后對(duì)每個(gè)組內(nèi)的salary列進(jìn)行求和,最終返回每個(gè)department_id的總工資金額。GROUP BY語(yǔ)句通常與聚合函數(shù)一起使用,以對(duì)每個(gè)分組進(jìn)行計(jì)算。

0