Summarizing Data with Summary Functions

Slides:



Advertisements
Similar presentations
About Functions SUM, AVERAGE, MIN, MAX, COUNT, ROUND
Advertisements

Database Programming Sections 5 & 6 – Group functions, COUNT, DISTINCT, NVL, GROUP BY, HAVING clauses, Subqueries.
Aggregating Data Using Group Functions. Objectives After completing this lesson, you should be able to do the following: Identify the available group.
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
Chapter 11 Group Functions
LECTURE 10.  Group functions operate on sets of rows to give one result per group.
11 Chapter 3: Displaying Query Results 3.1 Presenting Data 3.2 Summarizing Data.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
Introduction to Oracle9i: SQL1 SQL Group Functions.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Enhancements to the GROUP BY Clause Fresher Learning Program January, 2012.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Chapter 6 Group Functions. Chapter Objectives  Differentiate between single-row and multiple-row functions  Use the SUM and AVG functions for numeric.
Chapter 3 Single-Table Queries
SAS SQL Part 2 Alan Elliott. Dealing with Missing Values Title "Dealing with Missing Values in SQL"; PROC SQL; select INC_KEY,GENDER, RACE, INJTYPE, case.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Module 4: Grouping and Summarizing Data. Overview Listing the TOP n Values Using Aggregate Functions GROUP BY Fundamentals Generating Aggregate Values.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
Notes on SQL. SQL Programming Employers increasingly tell us that they look for 3 things on a resume: SAS, R and SQL. In these notes you will learn: 1.What.
Ms. Hall Spring Functions. Excel – Lesson 4 Summarizing Data with Functions A function is a predefined formula that performs a calculation. When.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Session 1 Retrieving Data From a Single Table
Applied Business Forecasting and Regression Analysis
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL AGGREGATE FUNCTIONS
Working with Tables: Join, Functions and Grouping
PROC SQL, Overview.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
(SQL) Aggregating Data Using Group Functions
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Noncorrelated subquery
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Aggregating Data Using Group Functions
Displaying Queries 2 Display a query’s results in a specified order.
Subsetting Rows with the WHERE clause
SQL – Entire Select.
Aggregations Various Aggregation Functions GROUP BY HAVING.
Outer Joins Inner joins returned only matching rows. When you join tables, you might want to include nonmatching rows as well as matching rows.
Chapter 4 Summary Query.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Grouping Summary Results
4.01 Spreadsheet Formulas & Functions
SQL Aggregation.
Exploring Microsoft® Office 2016 Series Editor Mary Anne Poatsy
4.01 Spreadsheet Formulas & Functions
Producing Descriptive Statistics
Lesson 4: Introduction to Functions
Reporting Aggregated Data Using the Group Functions
3 Specifying Rows.
Setting SQL Procedure Options
A new keyword -- calculated
Subqueries.
Reporting Aggregated Data Using the Group Functions
UNION Operator keywords Displays all rows from both the tables
Remerging Summary Values
Aggregate Functions.
Reporting Aggregated Data Using the Group Functions
Aggregate functions Objective- understand and able to use aggregate functions in select statement Aggregate functions are used to implement calculation.
Introduction to Spreadsheet Terminology
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Aggregating Data Using Group Functions
Group Operations Part IV.
Presentation transcript:

Summarizing Data with Summary Functions 2 Summarizing Data with Summary Functions

How a summary function works in SQL depends on the number of columns specified. If the summary function specifies only one column, the statistic is calculated for the column (using values from one or more rows). If the summary function specifies more than one column, the statistic is calculated for the row (using values from the listed columns).

The SUM Function (Review) SUM(argument1<,argument2, ...>)

Summary Functions -- include multiple columns to summarize by row. proc sql; select Employee_ID label='Employee Identifier', Qtr1,Qtr2,Qtr3,Qtr4, sum(Qtr1,Qtr2,Qtr3,Qtr4) label='Annual Donation' format=comma9.2 from orion.Employee_donations where Paid_By="Cash or Check" order by 6 desc ; quit; s103d05

Summary Functions – Include a single column to obtain the summary over all rows. proc sql; select sum(Qtr1) 'Total Quarter 1 Donations' from orion.Employee_Donations ; quit; title; s103d06

Summary Functions a comparison with proc means proc means data=orion.Employee_donations sum maxdec=0; var Qtr1; run; s103d06

The COUNT Function COUNT(*|argument) argument can be: * (asterisk) -- counts all rows a column name, counts the number of non-missing values in that column

Summary Functions – Find the number of active employees. proc sql; select count(*) as Count from orion.Employee_Payroll where Employee_Term_Date is missing ; quit; s103d07

Commonly used Summary Functions SQL SAS Description AVG MEAN returns the mean (average) value. COUNT FREQ, N returns the number of non-missing values. MAX returns the largest value. MIN returns the smallest non-missing value. SUM returns the sum of non-missing values. NMISS counts the number of missing values. STD returns the standard deviation. VAR returns the variance.

select 'The Average Salary is:', avg(Salary) proc sql; select 'The Average Salary is:', avg(Salary) from orion.Employee_Payroll where Employee_Term_Date is missing ; select 'The Mean Salary is:', mean(Salary) quit; title; Type answer here