dbms标识符无效_DBMS中的聚合运算符(分组依据和具有子句)
dbms標識符無效
綜合運營商 (Aggregate Operators)
To calculate aggregate values, one requires some aggregate operators to perform this task. These operators run over the columns of a relation. The total number of five aggregate operators is supported by SQL and these are:
為了計算合計值 ,需要一些合計運算符來執行此任務。 這些運算符在關系的列上運行。 SQL支持五個聚合運算符的總數,它們是:
COUNT – To calculate the number of values present in a particular column.
COUNT –計算特定列中存在的值的數量。
SUM – To calculate the sum of all the values present in a particular column.
SUM –計算特定列中所有值的總和。
AVG – To calculate the average of all the values present in a particular column.
AVG –計算特定列中所有值的平均值。
MAX – To find the maximum of all the values present in a particular column.
MAX –查找特定列中所有值的最大值。
MIN – To find the minimum of all the values present in a particular column.
MIN –查找特定列中所有值的最小值。
Mostly, with COUNT, SUM, and AVG, DISTINCT is specified in conjunction in order to eliminate any duplicate data. But for MAX and MIN, DISTINCT is not required to be specified as that will anyway not going to affect the output.
通常,使用COUNT , SUM和AVG時 ,將DISTINCT一起指定以消除任何重復數據。 但是對于MAX和MIN ,則不需要指定DISTINCT ,因為那樣將不會影響輸出。
For example: Find the average salary of all the employees.
例如:查找所有員工的平均工資。
SELECT AVG (E.salary) FROM Employee E按條款分組 (GROUP BY Clause)
GROUP BY Clause is used to group the attributes with similar features under the given condition.
GROUP BY子句用于在給定條件下對具有相似特征的屬性進行分組。
Let us consider a table of student.
讓我們考慮一張學生桌。
| 1 | Shiv | 89 | A |
| 2 | Parth | 78 | B |
| 3 | Ankush | 95 | A |
| 4 | Nimish | 83 | B |
| 1個 | 希夫 | 89 | 一個 |
| 2 | 帕斯 | 78 | 乙 |
| 3 | 安庫什 | 95 | 一個 |
| 4 | 尼米什人 | 83 | 乙 |
Question: Find the highest marks of the student for each section.
問題:找出每個部分學生的最高分數。
To find the highest marks section wise, we need to write two queries as:
為了明智地找到最高分,我們需要編寫兩個查詢:
SELECT MAX (S.Marks) FROM Student S WHERE S.Section = 'A' SELECT MAX (S.Marks) FROM Student S WHERE S.Section = 'B'As such, if we have many sections, we have to write the query that number of time. This looks quite lengthy.
這樣,如果我們有很多部分,我們必須以該次數編寫查詢。 這看起來很長。
GROUP BY clause made the solution easier as we don't require writing the queries the number of times of section, Instead, we write:
GROUP BY子句使解決方案更容易,因為我們不需要編寫查詢來查詢段的次數,而是編寫:
SELECT MAX (S.Marks) FROM Student S GROUP BY S.SectionIn this way, writing just one query, we will get the expected output.
這樣,只編寫一個查詢,我們將獲得預期的輸出。
| 3 | Ankush | 95 | A |
| 4 | Nimish | 83 | B |
| 3 | 安庫什 | 95 | 一個 |
| 4 | 尼米什人 | 83 | 乙 |
有條款 (HAVING Clause)
HAVING Clause determines whether the answer needs to be generated for a given condition or not.
HAVING子句確定是否需要為給定條件生成答案。
Let us consider the previous example.
讓我們考慮前面的例子。
| 1 | Shiv | 89 | A |
| 2 | Parth | 78 | B |
| 3 | Ankush | 95 | A |
| 4 | Nimish | 83 | B |
| 1個 | 希夫 | 89 | 一個 |
| 2 | 帕斯 | 78 | 乙 |
| 3 | 安庫什 | 95 | 一個 |
| 4 | 尼米什人 | 83 | 乙 |
Question: Find the highest marks of the student for each section having marks greater than 90.
問題:對于分數大于90的每個部分,找出學生的最高分數。
SELECT MAX (S.Marks) FROM Student S GROUP BY S.Section HAVING S.Marks > 90Thus, our output will be:
因此,我們的輸出將是:
| 3 | Ankush | 95 | A |
| 3 | 安庫什 | 95 | 一個 |
翻譯自: https://www.includehelp.com/dbms/aggregate-operators-group-by-and-having-clause-in-dbms.aspx
dbms標識符無效
總結
以上是生活随笔為你收集整理的dbms标识符无效_DBMS中的聚合运算符(分组依据和具有子句)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyBatis 的执行流程,学废了!
- 下一篇: Java Thread类的静态void