39 views

Uploaded by Anonymous rt8iK9pb

- DataPower Training Tutorial
- Analysis of variance.ppt
- new_oracle_w1.doc
- 174 SQL Queries
- Ace Pack
- Statistics and DOE Latest
- Outline_PPt_Week_2_Chapter+3
- Binom_Poisson
- Math Final
- Slides
- Coefficient of Determination
- Module in Measures of Variability
- davis_15_lp14.pdf
- ALLSLIDE SQL PLSQL-412
- E-V Example
- Tutorial 1 Questions
- Notes on Mathematical Expectation
- Dealership Evaluation Systems
- Principles of Geostatistic
- criteria query-new.docx

You are on page 1of 12

E nter U s erI D or E mail

Search :

By Sapna Malik November 02, 2010

In this article, we will learn aggregate function in Oracle.

Forgot Password Forgot Username Why Register Jump to Technology Website Sponsored by Become a Sponsor Resources About Us Authors News & Events Product Reviews Our Network .NET Heaven C# Corner Interview Corner Longhorn Corner VB.NET Heaven

Aggregate Function

Similar Articles

The aggregate functions return a SUM() Function in Oracle SQL Plus single value based on What is Aggregate Function ? groups of rows, rather than single How to use Maximun Aggregate operator in LINQ Partvalue for each row. 1 The aggregate Aggregate Functions in SQL : Part 2 functions ignore null Aggregating Data using Group Functions in Oracle values. We can use Aggregate functions More... in select lists and in ORDER BY and Sponsored by HAVING clauses. Become a Sponsor They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle divides the rows of a queried table or view into groups. All Aggregate Function: 1. 2. 3. 4. 5. 6. 7. 8. AVG Function CORR Function COUNT Function COVAR_POP Function COVER_SAMP Function GROUPING Function MAX Function MIN Function

REGR_(LINEAR REGRESSION) Functions STDDEV Function STDDEV_POP Function STDDEV_SAMP Function SUM Function VAR_POP Function VAR_SAMP Function VARIANCE Function

1. AVG Function: The AVG() function returns average value of expression. We can use it as an aggregate or analytic function. Syntax: SELECT AVG ("Expression") FROM "Table _Name"; Example: The following example calculates the average salary of all employees in the EMP5 table. SQL> SELECT AVG ("SALARY") 2 FROM EMP5; Output:

2. CORR Function: The CORR() function returns the coefficient of correlation of a set of number pairs. We can use it as an aggregate or analytic function. Both expression1 and expression2 are number expressions. Oracle applies the function to the set of (expression1 , expression2) after eliminating the pairs for which either expression1 or expression2 is null. Syntax: CORR( expression1 ,expression2) [ over (analytic_clause) ] Example: SQL> SELECT CORR(SALARY,EMP_ID) 2 FROM EMP5; Output:

3. COUNT Function: The COUNT() function returns the number of rows in the query. We can use it as an aggregate or analytic function. If we specify expression, COUNT returns the number of rows where expression is not null. We can count either all rows, or only distinct values of expression. If we specify the asterisk (*), this function returns all rows, including duplicates and nulls. COUNT never returns null. Syntax: SELECT COUNT(*) FROM Table_Name; Example: SQL> SELECT COUNT(*) "Total Row" 2 FROM EMP5; Output:

4. COVAR_POP() fUNCTION: The COVAR_POP() function returns the population covariance of a set of number pairs. We can use it as an aggregate or analytic function. The cover_pop function as a corr function. Syntax: COVAR_POP(expression1, expression2 ) Both expression1 and expression2 are number expressions. Oracle applies the function to the set of (expression1 , expression2) after eliminating the pairs for which either expression1 or expression2 is null.

5. COVER_SAMP Function: The COVER_SAMP() function returns the sample covariance of a set of number pairs. We can use it as an aggregate or analytic function. Syntax: COVAR_SAMP(expression1, expression2 ) Both expression1 and expression2 are number expressions. Oracle applies the function to the set of (expression1 , expression2) after eliminating the pairs for which either expression1 or expression2 is null. Example: SQL> SELECT COVAR_SAMP(SALARY,EMP_ID) 2 FROM EMP5; Output:

6. GROUPING Function: The GROUPING() function is applicable only in a select statement that contains a GROUP BY extension, such as ROLLUP or CUBE. These operations produce superaggregate rows that contain nulls representing the set of all values. You can use the GROUPING function to distinguish a null that represents the set of all values in a superaggregate

row from an actual null. Example: SQL> SELECT GROUPING(EMP_NAME) 2 FROM EMP5 3 GROUP BY "EMP_NAME"; Output:

7. MAX Function: The MAX()function returns maximum value of expression. We can use it as an aggregate or analytic function. Example: This example returns the highest salary. SQL> SELECT MAX(SALARY) 2 FROM EMP5; Output:

8. MIN Function: The MIN() function returns minimum value of expression. We can use it as an aggregate or analytic function. Example: This example returns the lowest salary. SQL> SELECT MIN(SALARY) 2 FROM EMP5; Output:

9. REGR_(LINEAR REGRESSION) Functions: The linear regression functions fit an ordinary-least-squares regression line to a set of number pairs. We can use them as both aggregate and analytic functions. The linear regression functions are: REGR_SLOPE REGR_INTERCEPT REGR_COUNT REGR_R2 REGR_AVGX REGR_AVGY REGR_SXX REGR_SYY REGR_SXY Oracle applies the function to the set of (expression1, expression2) pairs after eliminating all pairs for which either expression1 or expression2 is null. Oracle computes all the regression functions simultaneously during a single pass through the data. expression1 is interpreted as a value of the dependent variable (a "y value"), and expression2 is interpreted as a value of the independent variable (an "x value"). REGR_SLOPE() Function: The REGR_SLOPE()function returns the slope of the line. Example: SQL> SELECT REGR_SLOPE(SALARY,EMP_ID) 2 FROM EMP5; Output:

REGR_INTERCEPT Function: The REGR_INTERCEPT()function returns the y-intercept of the regression line. SQL> SELECT REGR_INTERCEPT(SALARY,EMP_ID) 2 FROM EMP5; REGR_COUNT Function: The REGR_COUNT()function returns an integer that is the number of non-null number pairs used to fit the regression line. SQL> SELECT REGR_COUNT(SALARY,EMP_ID) 2 FROM EMP5; REGR_R2 Function: The REGR_R2()function returns the coefficient of determination (also called "R-squared" or "goodness of fit") for the regression. SQL> SELECT REGR_R2(SALARY,EMP_ID) 2 FROM EMP5; REGR_AVGX Function: The REGR_AVGX()function evaluates the average of the independent variable (express12) of the regression line. SQL> SELECT REGR_AVGX(SALARY,EMP_ID) 2 FROM EMP5; REGR_AVGY Function: The REGR_AVGY()function evaluates the average of the dependent variable (express1) of the regression line. SQL> SELECT REGR_AVGY(SALARY,EMP_ID) 2 FROM EMP5; The REGR_SXY(), REGR_SXX(), REGR_SYY() function are auxiliary functions that are used to compute various diagnostic statistics. Example: REGR_SXX Function: SQL> SELECT REGR_SXX(SALARY,EMP_ID) 2 FROM EMP5; REGR_SYY Function: SQL> SELECT REGR_SYY(SALARY,EMP_ID) 2 FROM EMP5; REGR_SXY Function: SQL> SELECT REGR_SXY(SALARY,EMP_ID) 2 FROM EMP5; 10. STDDEV Function: The STDDEV() function returns sample standard deviation of expression, a set of numbers. We can use it as both an aggregate and analytic function. Oracle calculates the standard deviation as the square root of the variance defined for the VARIANCE aggregate function. Example:

11. STDDEV_POP Function: The STDDEV_POP() function computes the population standard deviation and returns the square root of the population variance Example: The following example returns the population and sample standard deviations of profit from salary in the EMP5 table. SQL> SELECT STDDEV_POP(SALARY) 2 FROM EMP5; Output:

12. STDDEV_SAMP Function: The STDDEV_SAMP() function computes the cumulative sample standard deviation and returns the square root of the sample variance. Example: SQL> SELECT STDDEV_SAMP(SALARY) 2 FROM EMP5; Output:

13. SUM Function: The SUM function returns the summed value of an expression. The expression can be a numeric field and formula. Syntax: SELECT SUM ("Expression") FROM "Table _Name"; Example: SQL> SELECT SUM ("SALARY") 2 FROM EMP5; Output:

14. VAR_POP Function: The VAR_POP() function returns the population variance of a set of numbers after discarding the nulls in this set. Example: SQL> SELECT VAR_POP(SALARY) 2 FROM EMP5; Output:

15. VAR_SAMP Function: The VAR_SAMP() function returns the sample variance of a set of numbers after discarding the nulls in this set Example: SQL> SELECT VAR_SAMP(SALARY) 2 FROM EMP5; Output:

16. VARIANCE Function: The VARIANCE() function returns variance of expression. We can use it as an aggregate or analytic function. Oracle calculates the variance of expression as follows: 0 if the number of rows in expression = 1 VAR_SAMP if the number of rows in expression > 1 Example: The following example calculates the variance of all salaries in the EMP5 table. SQL> SELECT VARIANCE(SALARY) 2 FROM EMP5; Output:

Thank you for reading this post. Please post your feedback, question, or comments about this post Here.

Login to add your contents and source code to this article About the author Looking for C # C onsulting? C # C onsulting is founded in 2002 by the founders of C # C orner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC , and Waterfall models. C lick here to learn more about C # C onsulting.

Comment Request!

Sapna Malik

Subject: Comment:

Submit

Comments

Hosted by | Found a | C ontact| Terms & | Privacy | Site MaximumASP broken link? Us conditions Policy Map 2011 contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.

Channels: Jobs | Interviews | C onsulting | Photos | Authors | Tips | Forums | E-Books | Training | Blogs Programming: C # | Visual Basic Sponsors: | ASP.NET & Web Development | C ++ | Other .NET Languages | Windows Vista | XAML | Tutorials

- DataPower Training TutorialUploaded bySorina Stoian
- Analysis of variance.pptUploaded bySomnath Banerjee
- new_oracle_w1.docUploaded byShashank Gupta
- 174 SQL QueriesUploaded byRaghavendra Kamurthi
- Ace PackUploaded bymarcos_de_carvalho
- Statistics and DOE LatestUploaded byMayank Garg
- Outline_PPt_Week_2_Chapter+3Uploaded byNick Chai
- Binom_PoissonUploaded byLiana Putri Maharani
- Math FinalUploaded byDianne Ruiz
- SlidesUploaded byayesha ameed
- Coefficient of DeterminationUploaded byJazib Ali Javed
- Module in Measures of VariabilityUploaded byCandy
- davis_15_lp14.pdfUploaded bybtec1005m
- ALLSLIDE SQL PLSQL-412Uploaded bySmita R. S.
- E-V ExampleUploaded byChinh Lê Đình
- Tutorial 1 QuestionsUploaded byILoveDubs
- Notes on Mathematical ExpectationUploaded byaef
- Dealership Evaluation SystemsUploaded byrajsajjan
- Principles of GeostatisticUploaded byErland Prasetya
- criteria query-new.docxUploaded byHaya Khawaja
- FunctionsUploaded byabdulgani11
- Introduction to NetezzaUploaded byenglishkaran
- 4.2 Variance AnalysisUploaded byPrabhakar Reddy
- SQL Tutorial.pdfUploaded byAkki ash
- Sample Preparation Composite and Replicate Strategy for Assay of Solid Oral Drug ProductUploaded bysamantha
- gender discriminationUploaded bymianusmanrasul
- Versi Terjemahan Dari ABSTRAK REVISIUploaded byTirta Sari
- SensIt Guide 145Uploaded bycmlim
- MySQL FuncionesUploaded byartur_martinez
- 10.1.1.115Uploaded byyusar_

- Oracle Exadata Experts HandBookUploaded bysamikcy
- Oracle Exadata Experts HandBookUploaded bysamikcy
- Oracledq Tutorial 132022Uploaded byAnonymous rt8iK9pb
- Document-Exadata-3.pdfUploaded byAnonymous rt8iK9pb
- Installing and Uninstalling Oracle Data Integrator and Oracle Data Quality ProductsUploaded byAnonymous rt8iK9pb
- Installing and Uninstalling Oracle Data Integrator and Oracle Data Quality ProductsUploaded byAnonymous rt8iK9pb
- interUploaded byAnonymous rt8iK9pb
- Oracle 10g regular expressionsUploaded byAnkan Majumdar
- 2675082 Oracle IndexesUploaded byajazkhank
- readme_enUploaded byAnonymous rt8iK9pb
- DataPumpUploaded byAnonymous rt8iK9pb

- Preparing Tracks for CD BurningUploaded byArtist Recording
- HistoryUploaded byThais Raqueli Rezende
- 5548c Ssu Br Screen2Uploaded bymanikantsanta
- Brochure - IPower for CIMPLICITY 9.5 (2017-01-V0.55)Uploaded byMạc David
- Manual ETANK2000Uploaded byEver Briceño
- G4000 BrochureUploaded byunlockvn
- Uninstall oracle9iUploaded bysujithsundar
- Integrating PHP and ABAP Using WebservicesUploaded byJulianholgado
- Circuit Cam40 TutorialUploaded byDede Sadi
- Introduction to the Security Engineering Risk Analysis (SERA) Framework.pdfUploaded byPinnacle Systems Group
- Run Os x Mavericks 10.9Uploaded byMihaela Caciumarciuc
- Electronic Circuits and Pulse Circuits Lab ManualUploaded byPriya Varenya
- 115JUploaded byMarcelo Sánchez
- dd_s04_l02Uploaded bySladjan Ugrenovic
- Ee6008 Mcbsd Apr May 2017Uploaded byRavi
- Altium Designer 14 Feature Set SummaryUploaded byMd Sumon
- PRO Monitoring User's Manual Appendix Rev 1_2Uploaded byDiego Santana Bragança
- 10.1.1.34Uploaded byluftkissen
- FINACLE CRMUploaded byNitika Gupta
- 200v4lab_00_pss_Uploaded byMuhammad Dirwan Bahri
- Example Quality PlanUploaded byzafeer
- Avaya 1603 ManualUploaded byatiq_masw
- Eurotherm 2404 PDFUploaded byMaggie
- PH3210.pdfUploaded bynairoluis
- Elearn Security TemarioUploaded byjuliangarciaz
- Rellks.pdfUploaded bysanjeev
- Tcl_1_2004.12_SG_e.pdfUploaded bySiva Badri
- Install KohaUploaded byawansn1984
- Assembling a Code-Practice OscillatorUploaded byTheZodiacKiller
- Grading Rubrics for a Powerpoint Presentation ProjectUploaded byCris Calitina