Texas State Technical College DISCOVER! Aggregate Functions It’s a group thing.

Slides:



Advertisements
Similar presentations
Database Programming Sections 5 & 6 – Group functions, COUNT, DISTINCT, NVL, GROUP BY, HAVING clauses, Subqueries.
Advertisements

5 Copyright © 2007, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
Chapter 11 Group Functions
LECTURE 10.  Group functions operate on sets of rows to give one result per group.
Introduction to Oracle9i: SQL1 SQL Group Functions.
Structured Query Language Part I Chapter Three CIS 218.
Mary K. Olson PS Reporting Instance – Query Tool 101.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
Mean, Median, and Mode An Introduction to Data Management: Measures of Central Tendencies.
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
SQL 資料庫查詢語言 取材自 EIS, 3 rd edition By Dunn et al..
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
WORKING WITH STRUCTURED DATA (1/3) Functional ICT.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Consumer Loans © 2010 Pearson Education, Inc. All rights reserved.Section 9.3, Slide Determine payments for an add- on loan. Compute finance charges.
Using Special Operators (LIKE and IN)
DATABASE TRANSACTION. Transaction It is a logical unit of work that must succeed or fail in its entirety. A transaction is an atomic operation which may.
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?
Views Lesson 7.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
M M M R.
Mean: The AVERAGE values of a set of numbers. The mean is found by ADDING all of the values, then DIVIDING by the number of values in the set of data.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Texas State Technical College DISCOVER! Cartesian Product Cover all the bases.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Course title: Database-ii Chap No: 03 “Advanced SQL” Course instructor: ILTAF MEHDI.
Single-Table Queries 2: Advanced Topics CS 320. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data SELECT field1, field2,
Structured Query Language SQL Unit 4 Solving Problems with SQL.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Relational Databases Today we will look at: Different ways of searching a database Creating queries Aggregate Queries More complex queries involving different.
Structured Query Language
Statistical Measures M M O D E E A D N I A R A N G E.
Structured Query Language (Data Manipulation Language)
Aggregating Data Using Group Functions
Group Functions Lab 6.
Chapter 5: Aggregate Functions and Grouping of Data
Measures of Central Tendency & Range
Aggregating Data Using Group Functions
SQL FUNDAMENTALS CDSE Days 2018.
(SQL) Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
SQL – Entire Select.
Chapter 4 Summary Query.
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
Measures of Central Tendency (Mean, Median, & Mode)
Access: SQL Participation Project
SQL Aggregation.
Exploring Microsoft® Office 2016 Series Editor Mary Anne Poatsy
Reporting Aggregated Data Using the Group Functions
Query Functions.
Access: Queries III Participation Project
Projecting output in MySql
Reporting Aggregated Data Using the Group Functions
Set Operations Union Intersect Minus.
Aggregate Functions.
Reporting Aggregated Data Using the Group Functions
Mean.
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
LINQ to SQL Part 3.
Aggregating Data Using Group Functions
Group Operations Part IV.
Presentation transcript:

Texas State Technical College DISCOVER! Aggregate Functions It’s a group thing.

Texas State Technical College DISCOVER! Aggregate Functions At times, it may be necessary to obtain information about the entire set of records obtained from a SELECT statement. Such information might include a field maximum, minimum, average, or count. Aggregate functions calculate information across a group or set of records. Overview

Texas State Technical College DISCOVER! Aggregate functions work in an aggregate mode. Any fields or calculations given as a parameter to an aggregate function are accessed/calculated for every record in the group. Overview Aggregate Functions

Texas State Technical College DISCOVER! The most common aggregate functions are as follows: count() Counts either all records or the number of records that have a value in a field.count() Counts either all records or the number of records that have a value in a field. avg() Calculates the average value across a field in a group.avg() Calculates the average value across a field in a group. sum() Calculates the total of all the values in a field for the group.sum() Calculates the total of all the values in a field for the group. max() Calculates the maximum value in the group.max() Calculates the maximum value in the group. min() Calculates the minimum value in the group.min() Calculates the minimum value in the group. Common Aggregate Functions Aggregate Functions

Texas State Technical College DISCOVER! Determines either the number of records in the group or the number of records with a value in a field Syntax Number count(*) Counts all records Number count(FIELD fieldname) Counts records where value in fieldname is NOT NULL ExampleSELECTcount(*)FROMborrower; Count Aggregate Functions

Texas State Technical College DISCOVER! Determines the average value for a field or calculation across all records. Syntax Number avg(FIELD fieldName | CALCULATION cValue) ExampleSELECT avg(debt)AS “Average Customer Debt”, avg(debt – paid) AS “Average Customer Balance” FROMborrower; Avg Aggregate Functions

Texas State Technical College DISCOVER! Determines the total value across a set of records. Syntax Number sum(FIELD fieldName | CALCULATION cValue) ExampleSELECT sum(debt)AS “Total Debt Due Company”, sum(debt – paid)AS “Total Balance Owed to Company” sum(debt – paid)AS “Total Balance Owed to Company”FROMborrower; Sum Aggregate Functions

Texas State Technical College DISCOVER! Determines the maximum value in a field or calculation across a set of records. Syntax Number max(FIELD fieldName | CALCULATION cValue) ExampleSELECT max(debt)AS “Greatest Borrower”, max(debt – paid)AS “Greatest Delinquent Borrower” max(debt – paid)AS “Greatest Delinquent Borrower”FROMborrower; Max Aggregate Functions

Texas State Technical College DISCOVER! Determines the minimum value in a field or calculation across a set of records. Syntax Number min(FIELD fieldName | CALCULATION cValue) ExampleSELECT min(debt)AS “Least Borrower”, min(debt – paid)AS “Least Delinquent Borrower” min(debt – paid)AS “Least Delinquent Borrower”FROMborrower; Min Aggregate Functions

Texas State Technical College DISCOVER! The function itself is aggregate; it works across a group of records. However, the function must operate at a single- row level to retrieve the field or calculation value from each record. The parameters given to an aggregate function are evaluated in a single-row mode. Important Aggregate Functions

Texas State Technical College DISCOVER! In the function sum(debt) the field value of debt is evaluated for each and every record in the group and the result is added to the group sum. In the function sum(debt – paid) sum(debt – paid) the calculation (debt – paid) is evaluated for each and every record in the group and the result is added to the group sum. For Example… Aggregate Functions

Texas State Technical College DISCOVER! When used alone, aggregate functions see all the records in a SELECT statement as one complete group. To further divide the records into subgroups, use the GROUP BY statement. At this point, the SELECT statement will apply to each GROUP and the aggregate function will calculate for each group. Caveats Aggregate Functions

Texas State Technical College DISCOVER! In Summary… Aggregate functions calculate information about a set or group of records. The parameters to aggregate functions are evaluated at the single-row level. By default, they group all the records in the return set into one group. If a GROUP BY statement is used, the aggregate functions perform calculations for each group. Aggregate Functions