Built in Functions Massaging the data.

Slides:



Advertisements
Similar presentations
SQL (2).
Advertisements

Database Programming Sections 5 & 6 – Group functions, COUNT, DISTINCT, NVL, GROUP BY, HAVING clauses, Subqueries.
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
Chapter 11 Group Functions (up to p.402)
Introduction to Oracle9i: SQL1 SQL Group Functions.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
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.
Computer Science 101 Web Access to Databases SQL – Extended Form.
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 6 Group Functions. Chapter Objectives  Differentiate between single-row and multiple-row functions  Use the SUM and AVG functions for numeric.
INLS 623– S QL Instructor: Jason Carter. SQL SELECT DISTINCT SELECT DISTINCT column_name, column_name FROM table_name ;
Using Special Operators (LIKE and IN)
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?
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
Chapter 11 Functions and Groups Part C. SQL Copyright 2005 Radian Publishing Co.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SQL Aggregation Oracle and ANSI Standard SQL Lecture 9.
IFS180 Intro. to Data Management Chapter 11 - Subqueries.
Module 4: Grouping and Summarizing Data. Overview Listing the TOP n Values Using Aggregate Functions GROUP BY Fundamentals Generating Aggregate Values.
1 SY306 Web and Databases for Cyber Operations Set #13: SQL SELECT Grouping and sub-queries.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
IS6146 Databases for Management Information Systems Lecture 4: SQL IV – SQL Functions and Procedures Rob Gleasure robgleasure.com.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
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.
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.
SQL Reminder Jiankang Yuan Martin Lemke. SQL Reminder - SELECT SELECT column_name1, column_name2, … FROM table_name SELECT * FROM table_name.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 9: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
SQL Query Getting to the data ……..
CS3220 Web and Internet Programming More SQL
Structured Query Language
Rob Gleasure robgleasure.com
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Lab 13 Databases and SQL.
SQL AGGREGATE FUNCTIONS
The Database Exercises Fall, 2009.
Working with Tables: Join, Functions and Grouping
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL : Query Language Part II CS3431.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
MENAMPILKAN DATA DARI SATU TABEL (Chap 2)
Chapter 11 Functions and Groups
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Rob Gleasure robgleasure.com
Access Quiz.
SQL – Entire Select.
Aggregations Various Aggregation Functions GROUP BY HAVING.
Chapter 4 Summary Query.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
SQL Aggregation.
Structured Query Language – The Fundamentals
CS122 Using Relational Databases and SQL
Query Functions.
Section 4 - Sorting/Functions
Aggregate Functions.
LINQ to SQL Part 3.
Shelly Cashman: Microsoft Access 2016
Group Operations Part IV.
Presentation transcript:

Built in Functions Massaging the data

Functions SQL includes several built in functions They all operate with the same pattern SELECT FunctionName(Function arguments) FROM Tablename Function can be nested inside of each other SELECT MAX(SUM(Rate*Hours)

ALIASING You can give a return column generated by a function a name or Alias SELECT MAX(Rate) AS Highest SELECT MAX(Rate) “Highest”

Most Common Functions COUNT MAX MIN SUM AVG

Count COUNT counts the number of rows that meet a certain criteria. It can be used on textual as well as numeric data SELECT Count(*) FROM Orders SELECT COUNT(CarrierCode) as ALASKA FROM ItinerayDetail WHERE CarrierCode=‘ALA’

MAX MAX returns the largest value in a column. It can only be used with numeric fields and dates SELECT MAX(Price) FROM Inventory

MIN Returns the lowest value in a column (again numeric or date) SELECT MIN(RATE) FROM HourlyRate

SUM SUM Returns the total of numeric column SELECT SUM(points) FROM Assignment WHERE StudentID=‘980001111’

AVG AVG Returns the mean Average of a numeric column SELECT AVG(heartrate) FROM Excercise

Aggregate Functions All the functions that we have looked at are called aggregate functions That means they work on groups of rows or values, rather than just one row or one value

GroupBy If you include any columns in the SELECT of a query with an aggregate function you must GROUP BY those columns SELECT StudentID, SUM(points) FROM Assignments GROUP BY StudentID

Having Like the WHERE clause, but WHERE operates on individual records HAVING operates on Aggregrate (grouped) records SELECT EmployeeID, COUNT(OrderID) AS NumOrders FROM ORDERS GROUP BY EmployeeID HAVING COUNT(OrderID)>100

Example SubQuery SELECT Orderid, unitprice FROM SaleDetail WHERE Unitprice= (SELECT MAX (UnitPrice) FROM SaleDetail