Chapter 4 Summary Query.

Slides:



Advertisements
Similar presentations
Murach's MySQL, C3© 2012, Mike Murach & Associates, Inc.Slide 1.
Advertisements

4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
5 Copyright © 2007, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
4 การใช้ SQL Functions. Copyright © 2007, Oracle. All rights reserved What Are Group Functions? Group functions operate on sets of rows to give.
Chapter 11 Group Functions
CpSc 3220 The Language of SQL Chapters Summarizing Data Most SQL functions apply to scalar arguments SUMMARY or AGGREGATE functions apply to rows.
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.
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.
Computer Science 101 Web Access to Databases SQL – Extended Form.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
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
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 4 BACKNEXTEND 4-1 LINKS TO OBJECTIVES Query Design Query Criteria Modify a Query Using OR.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
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.
Using Special Operators (LIKE and IN)
SQL Data Manipulation II Chapter 5 CIS 458 Sungchul Hong.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
IST 210 SQL Todd Bacastow IST 210: Organization 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.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL Aggregation Oracle and ANSI Standard SQL Lecture 9.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Course title: Database-ii Chap No: 03 “Advanced SQL” Course instructor: ILTAF MEHDI.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
Module 4: Grouping and Summarizing Data. Overview Listing the TOP n Values Using Aggregate Functions GROUP BY Fundamentals Generating Aggregate Values.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
SQL: Single Table Queries SELECT FROM WHERE ORDER D. Christozov / G.Tuparov INF 280 Database Systems: Single Table Queries 1.
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
SQL queries ordering and grouping. SWC – SQL query - ordering In a query producing a large result, it may be beneficial to order the result SQL.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
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.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
SQL Query Getting to the data ……..
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
© 2016, Mike Murach & Associates, Inc.
Chapter 5: Aggregate Functions and Grouping of Data
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
MENAMPILKAN DATA DARI SATU TABEL (Chap 2)
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Aggregating Data Using Group Functions
GROUP BY & Subset Data Analysis
SQL – Entire Select.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Access: SQL Participation Project
Structured Query Language
Reporting Aggregated Data Using the Group Functions
Query Functions.
Section 4 - Sorting/Functions
Reporting Aggregated Data Using the Group Functions
Reporting Aggregated Data Using the Group Functions
分组函数 Schedule: Timing Topic 35 minutes Lecture 40 minutes Practice
Shelly Cashman: Microsoft Access 2016
Aggregating Data Using Group Functions
Group Operations Part IV.
Presentation transcript:

Chapter 4 Summary Query

บทที่ 4 การประมวลผลฐานข้อมูลเชิงธุรกิจ (Summary Query) ฝึกปฏิบัติการการประมวลผลฐานข้อมูลเชิงธุรกิจ (SQL, Join, and Summary Query)

Agenda How to code summary queries 1. How to work with aggregate functions 2. How to group and summarize data

1. How to work with aggregate functions

Aggregate Functions Sometimes referred as column functions and summary queries. Aggregate functions operate on the values in columns.

Syntax of the Aggregate Functions

Syntax of the Aggregate Functions Aggregate functions called column functions, perform a calculation on the values in a set of selected rows SELECT statement includes one or more aggregate functions AVG and SUM functions must result in a numeric value MIN, MAX, and COUNT functions can result in numeric, date, or string value Use DISTINCT keyword to omit duplicate values (typically used with the COUNT function) All of the aggregate functions except for COUNT (*) ignore null values The SELECT statement includes a GROUP BY clause, the SELECT clause can include the columns user for grouping, aggregate functions, and expressions that result in a constant value

A Summary Query that counts unpaid invoice and calculates the total due Calculate selected values in a set of selected rows

A Summary Query that use the COUNT(*), AVG, and SUM functions

A Summary Query that use the MIN and MAX functions

A Summary Query that Works on non-numeric columns

A Summary Query that uses the DISTINCT keyword To count all of the selected rows Use COUNT (*) function Use COUNT function with the name of any column that can’t contain null values Use DISTINCT keyword to count only the rows with unique values in a specified column

2. How to group and summarize data

Group and summarize data Using GROUP BY and HAVING clauses

Syntax of the SELECT statement with GROUP BY and HAVING clauses

A summary Query that calculates the average invoice amount by vendor

A summary query that counts the number of invoices by vendor

A summary query that calculates the number of invoices and the average invoice amount for the vendors in each state and city

A summary query that limits the groups to those with two or more invoices

How the HAVING clause compares with the WHERE clause Can contain aggregate function Can’t contain aggregate function Can refer to columns included in the SELECT clause Can refer to any columns in the base tables

A summary query with a search condition in the HAVING clause

A summary query with a search condition in the WHERE clause

How to code compound search conditions

A summary query with compound condition in the HAVING clause

The same query code with a WHERE clause

How to use the WITH ROLLUP operator WITH ROLLUP operator can add one or more summary rows to the result set that uses grouping and aggregates

A summary query that includes a final summary row Group by a single column Group the invoices by vendor_id and calculates an invoice count and invoice total for each vendor group This query adds a summary row to the end of the result set

A summary query that includes a summary row for each grouping level Group by two columns This query groups vendors by state and city and counts the number of vendors in each group This query adds a summary row to the end state and adds a final summary row at the end of result set

WITH ROLLUP The WITH ROLLUP operator adds a summary row for each group specified in the GROUP BY clause. It also adds a summary row to the end of the result set that summarizes the entire result set. If the GROUP BY clause specifies a single group, the WITH ROLLUP operator only adds the final summary row When you use the WITH ROLLUP operator, you can’t use the ORDER BY clause. You can code the ASC or DESC keyword after the column in the GROUP BY clause to sort individual columns When you use the WITH ROLLUP operator, you can’t use the DISTINCT keyword in any of the aggregate functions.

Questions

References Murach, J. (2012). Murach’s SQL. Mike Murach & Associates, Inc. http://faculty.tnstate.edu/Oracle10g/text/Chapter% 205.pdf http://www.cs.utexas.edu/~cannata/dbms/Homew ork/My%20Guitar%20Shop%20Chapter%205.pdf http://www.w3schools.com/sql/default.asp