Attribution Non-Commercial (BY-NC)

39 views

Attribution Non-Commercial (BY-NC)

- Anemiaaa
- SQL Fundamentals II - Practice Solutions
- Oracle Nipuna Queries on Emp Table
- 0295-5075_89_3_38007
- statistik tugas
- sampl Project Format
- Relational Algrebra
- SQL
- kisi-kisi
- Perceptions
- main.java
- Login Panel
- Untitled
- PERT-KR
- Goldengate 12c
- 15018544
- Prediction on House Asking Price in Jinjang
- H2 Mathematics Cheat Sheet by Sean Lim
- macroeconomic.pdf
- QTA Interpretation

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

- AnemiaaaUploaded byAgun Fauzi
- SQL Fundamentals II - Practice SolutionsUploaded byНЛесс
- Oracle Nipuna Queries on Emp TableUploaded byypraju
- 0295-5075_89_3_38007Uploaded byporporkis09
- statistik tugasUploaded byDyana Putri
- sampl Project FormatUploaded bysaoodalam90_56968256
- Relational AlgrebraUploaded byFarouk Althlathini
- SQLUploaded bySourabh Dhingra
- kisi-kisiUploaded byronzp
- PerceptionsUploaded byerliatj
- main.javaUploaded bymohan_rm
- Login PanelUploaded byKalyan Sundaram
- UntitledUploaded byapi-233084441
- PERT-KRUploaded byjainvikram8498
- Goldengate 12cUploaded bysumegupt
- 15018544Uploaded bymac
- Prediction on House Asking Price in JinjangUploaded bysadyehclen
- H2 Mathematics Cheat Sheet by Sean LimUploaded byGale Hawthorne
- macroeconomic.pdfUploaded byAroosa Khawaja
- QTA InterpretationUploaded byMuhammad Haris
- l 1 Mock v 42016 December Am SolutionsUploaded byCratos_Poseidon
- IE211 SyllabusUploaded bySam Matuba
- Book11Uploaded byParitosh Tonk
- java----intUploaded byravitej
- A2Uploaded byNauman Shakir
- Document 988907.1Uploaded bysegador2000
- daadaUploaded bycak myt
- Landscape MetricsUploaded bycintia
- Phase Angle and Its Determinants in Healthy Subjects- Influence of Body CompositionUploaded byraquelgl28
- ch4sol.pdfUploaded byJitendra Kumar

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

- Maslow 1948Uploaded bySujit Sekhar
- NSTP OrientationUploaded byCriselda Cabangon David
- Coffee&Tea Vending Machine ReportUploaded byMarcos Dal Pont
- Kelly Cahill EncounterUploaded byJuan Cabezas
- Neurath, Arntz and ISOTYPEUploaded byalisstorrent
- Challenges & Opportunities for EntrepreneursUploaded byprabhatrc4235
- SQL InjectionsUploaded bySaba Wasim
- My Journey to Cracking Steganography Mission 15Uploaded byКийпър Петров
- Unit5 Statistics MATH2(D) IkbnUploaded byAzizul Anwar
- Chapter 4 Transient Conduction - Part 1 - HandoutUploaded byGunasegaran Mokhan
- Caterpillar-CCM-ForDieselEngines.pdfUploaded byAnonymous M0OEZEKoGi
- Library House - Metrics for the Evaluation of Knowledge Transfer ActivitiesUploaded bySynalytic
- SAP Interface DesignUploaded byImran Tamboli
- Ficha Técnica Del Agua de Palmira, ValleUploaded byJesusDavidSierra
- Analog and DigitalUploaded byKalai Yarasi
- wdtdriverspecUploaded byJesus Marsa
- debate 2Uploaded byapi-256056875
- 321782458-CC-dorksUploaded bySmith Lizaraso
- PPAP ElementsUploaded bySenthil Kumar Gunasekaran
- gen+phil+mind-body+handoutUploaded byBob Krueger
- 2.3 Complex NumbersUploaded byRakesh S India
- Practice+exam+Part+1.pdfUploaded bydaoud saleem
- lab3_Verilog.pdfUploaded byTuân Phạm
- Ethan Frome Online PDFUploaded byKaren
- Employee MotivationUploaded byAngie Stamatiou
- Gravity SurveysUploaded byvelkus2013
- bpj lesson 4Uploaded byapi-307093783
- Algebra Word Problem Solver FreeUploaded bycircleteam123
- Quantusum ExcerptUploaded byAndrei Iacob
- Pp t 0000027Uploaded byumesh