Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Aggregate.

Slides:



Advertisements
Similar presentations
Database Fundamentals
Advertisements

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Self-joins,
Microsoft Enterprise Consortium Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Database Fundamentals Defining.
Introduction to OBIEE:
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Create Student-Team.
SharePoint slide libraries II: Use slides in the slide library MICROSOFT ® OFFICE SHAREPOINT ® SERVER 2007 TRAINING ADVANTAGE TALENT, INC. “Professionals.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals The Data.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Data.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Evaluating.
Microsoft ® Office Excel ® 2007 Training Get started with PivotTable ® reports [Your company name] presents:
Chapter 2 Querying a Database
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Greenhouse Database.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Type II (Correlated)
Accessing Predefined Reports, Cubes, and Ad Hoc Presented By: Jennifer Hancock April 2010.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Introduction.
Microsoft ® Office SharePoint ® Server 2007 Training SharePoint calendars I: Make the most of your team calendar Bellwood-Antis School District presents:
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Download three SQL script files from wiki page.
Before you begin If a yellow security bar appears at the top of the screen in PowerPoint, click Enable Editing. You need PowerPoint 2010 to view this presentation.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Using two.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SQL Server.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Test.
Microsoft ® Office SharePoint ® Server 2007 Training Excel Services II: Requirements, recommendations, and permissions [Your company name] presents:
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SELECT … FROM.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Nested aggregate.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Aggregating.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
Monthly Special Education Coordinator Meeting November 2014.
Return To Index Excel Microsoft Excel Basics Lesson 02 Excel Help Facilities Help WizardHelp Wizard - 2 Menu Toolbar Help Option - 4 Menu Toolbar.
CS1100: Microsoft Access Managing Data in Relational Databases Created By Martin Schedlbauer CS11001Microsoft Access - Introduction.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SELECT … FROM.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
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.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Sorting output.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Logical operators.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL In-Line Subquery.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Equi-Join One-sided.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Set Operators:
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals WHERE clause.
1 Connecting to a Database Server. 2 We all have accounts, with a single database each, on a Microsoft SQL Server on the USF network: allman.forest.usf.edu.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL The relational.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Data.
Cameron Blashka| Informer Implementation Specialist
NURS6803 Clinical DB Design Katherine Sward, PhD, RN
Using Subqueries to Solve Queries
Microsoft Enterprise Consortium Type I Subquery
Database Fundamentals
Lesson 12.
Access: SQL Participation Project
Using Subqueries to Solve Queries
Introduction to Database Programs
M1G Introduction to Database Development
Reporting Aggregated Data Using the Group Functions
From and Report.
Using Subqueries to Solve Queries
Introduction to Database Programs
Joins and other advanced Queries
Topic 12 Lesson 2 – Retrieving Data with Queries
Reporting Aggregated Data Using the Group Functions
Using Subqueries to Solve Queries
Reporting Aggregated Data Using the Group Functions
Use of SQL – The Patricia database
Presentation transcript:

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Aggregate data and the HAVING clause 1 Microsoft Enterprise Consortium Microsoft Enterprise Consortium: Microsoft Faculty Connection/Faculty Resource Center

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium What you’ll need … Log in to MEC for this lesson and into MSSMS (Microsoft SQL Server Management Studio). ◦Be sure to select your account ID under Database in the Object Explorer pane, similar to the example shown here. If there is something besides the topics for this lesson that you’re not familiar with in this presentation, please review earlier lessons in this SQL Fundamental series. 2

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium GROUP BY – aggregating data Sometimes when we aggregate data, we also want to filter the output based on the aggregated values. Before filtering, a school might want a list of how many students are in each course in the fall and spring semesters. The grouping shown here is based on the year, then by semester, then by course. 3 YearSemesterCourseStudent Count 2010FallENG30146 FallMAT30135 SpringENG30151

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium GROUP BY and HAVING What if the list should only show classes with more than 40 students? If that’s the case, the aggregated data we saw on the previous slide would filter out one row. 4 YearSemesterCourseStudent Count 2010FallENG30146 FallMAT30135 SpringENG30151 YearSemesterCourseStudent Count 2010FallENG30146 SpringENG30151

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium GROUP BY clause First, let’s look at the aggregate query: Show the evaluation scores for each student in each team. select std_teamid as "Team ID", stdid as "Student ID", eval_item_ID as "Eval Item", avg(score) as "Average Score” from students join evaluations on stdid = evaluateeID join eval_items_scores on evaluations.eval_ID = eval_items_scores.eval_ID group by std_teamid, stdid, eval_item_ID order by std_teamid, stdid, eval_item_ID; 5

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium GROUP BY with a HAVING clause Next, let’s add a filter criterion in the HAVING clause. Show the evaluation scores for each student in each team if their average is above 95. select std_teamid as "Team ID", stdid as "Student ID", eval_item_ID as "Eval Item", avg(score) as "Average Score” from students join evaluations on stdid = evaluateeID join eval_items_scores on evaluations.eval_ID = eval_items_scores.eval_ID group by std_teamid, stdid, eval_item_ID HAVING avg(score) > 95 order by std_teamid, stdid, eval_item_ID; 6

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Another HAVING clause example Next, let’s add a filter criterion in the HAVING clause. Show the evaluation scores for each student in each team if their average is below 80. select std_teamid as "Team ID", stdid as "Student ID", eval_item_ID as "Eval Item", avg(score) as "Average Score” from students join evaluations on stdid = evaluateeID join eval_items_scores on evaluations.eval_ID = eval_items_scores.eval_ID group by std_teamid, stdid, eval_item_ID HAVING avg(score) < 80 order by std_teamid, stdid, eval_item_ID; 7

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium WHERE and HAVING clauses We can filter individual rows in the WHERE clause and the aggregate values in the HAVING clause. select std_teamid as "Team ID", stdid as "Student ID", eval_item_ID as "Eval Item", avg(score) as "Average Score” from students join evaluations on stdid = evaluateeID join eval_items_scores on evaluations.eval_ID = eval_items_scores.eval_ID WHERE std_teamid = 'SYSDES' group by std_teamid, stdid, eval_item_ID HAVING avg(score) < 80 order by std_teamid, stdid, eval_item_ID; 8

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium What was covered … HAVING clause for aggregate values ◦Filter output based on aggregate value criteria. HAVING versus WHERE criteria ◦Aggregate versus detail (row by row) criteria 9

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Resources Microsoft Faculty Connection—Faculty Resource Center Microsoft Transact-SQL Reference AdventureWorks Sample Database 10