1 All Powder Board and Ski SQL Server Workbook Chapter 4: Queries Jerry Post Copyright © 2003.

Slides:



Advertisements
Similar presentations
All Powder Board and Ski
Advertisements

1 All Powder Board and Ski Microsoft Access Workbook Chapter 9: Data Warehouses and Data Mining Jerry Post Copyright © 2007.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2007.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 6: Forms and Reports Jerry Post Copyright © 2007.
CC SQL Utilities.
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Chapter 5 Creating, Sorting, and Querying a Table
Exploring Microsoft Excel 2002 Chapter 7 Chapter 7 List and Data Management: Converting Data to Information By Robert T. Grauer Maryann Barber Exploring.
Managing Grades with Excel Viewing Help To view Help 1.Open Excel on your computer. 2.In the top right hand corner of the Excel Screen type in the.
5 Chapter 5 Structured Query Language (SQL2) Revision.
Introduction to Structured Query Language (SQL)
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Concepts of Database Management Sixth Edition
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Working with Queries in Microsoft Access The Access Workbench: Section Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 4: Queries Jerry Post Copyright © 2007.
Chapter 5 Advanced Querying
Analyzing Data For Effective Decision Making Chapter 3.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 7: Integrity and Transactions Jerry Post Copyright © 2003.
1 All Powder Board and Ski SQL Server Workbook Chapter 2: Database Design Jerry Post Copyright © 2004.
Excel Project 2 Formulas, Functions, and Formatting.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 10: Distributed Databases Jerry Post Copyright © 2003.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 9: Database Administration Jerry Post Copyright © 2003.
Concepts of Database Management Seventh Edition
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Microsoft Access 2007 Tutorial (Part II) CIS*1000*DE.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 4: Queries Jerry Post Copyright © 2003.
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.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
1 All Powder Board and Ski Oracle 9i Workbook Chapter 10: Distributed Databases Jerry Post Copyright © 2003.
A Guide to SQL, Seventh Edition. Objectives Understand how to use functions in queries Use the UPPER and LOWER functions with character data Use the ROUND.
XP. Objectives Sort data and filter data Summarize an Excel table Insert subtotals into a range of data Outline buttons to show or hide details Create.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 6: Forms, Reports, and Applications Jerry Post Copyright © 2003.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 8: Data Warehouses and Data Mining Jerry Post Copyright © 2003.
All Powder Board and Ski Microsoft Access Workbook Chapter 2: Database Design Jerry Post Copyright © 2003.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 8: Data Warehouses and Data Mining Jerry Post Copyright © 2003.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 4: Queries Jerry Post Copyright © 2003.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Working with Data Lists.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2003.
Microsoft® Excel Create an Excel table. 1 Work with the Table Tools Design tab. 2 Sort and filter records in a table. 3 Identify structured references.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 6 BACKNEXTEND 6-1 LINKS TO OBJECTIVES Using the Report Button Using the Report Button Print.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
1 All Powder Board and Ski SQL Server Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2003.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
IFS180 Intro. to Data Management Chapter 10 - Unions.
McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 10: Distributed Databases and the Internet All Powder.
McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9: Database Administration All Powder Board and Ski.
3 A Guide to MySQL.
Chapter 6: Forms, Reports and Applications All Powder Board and Ski
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
PIVOT TABLE BASICS.
Chapter 2: Database Design All Powder Board and Ski
All Powder Board and Ski
All Powder Board and Ski
Lesson 13 Working with Tables
Presentation transcript:

1 All Powder Board and Ski SQL Server Workbook Chapter 4: Queries Jerry Post Copyright © 2003

2 Primary Tables

3 Action Copy files from BuildAllPowder. Drop or rename conflicting tables. Switch to command mode. Run the batch file BuildAllPowderSQL server username password Check the tables.

4 File/Get External Data/Import (1)Copy BuildAllPowder folder to machine running SQL Server (2)Drop or rename any conflicting tables (1)By hand (2)In SQL Plus, run the file DropAllPowderTablesSQL.sql (3)Switch to command mode: Start/All Programs/Accessories/Command Prompt (4)BuildAllPowderSQL server username password

5 All Powder Tables After Import

6 Starting a Query: Query Analyzer SQL statement Results Database connection Execute query Default database

7 Enterprise Manager View Results SQL text Tables and Joins Execute query Database

8 Action Start a new View. Right-click and Add the ItemModel table. Select columns: Category, ListPrice, WeightMax, Color, and Graphics. Enter conditions: Category=’Board’ AND ListPrice 150. Check the SQL text. Run the query.

9 Sample Query Display snowboards with a list price under $300 and max weight over 150 pounds. SQL Results Tables Constraints

10 More Complex Query Ski for jumping. Composite material. Red or Yellow main color. Yellow skis must be under $300. Red skis must be under $400 Three main conditions WHERE Category=‘Ski’ AND ItemMaterial=‘Composite’ AND Style=‘Jump’

11 Action Start a new query. Add the ItemModel table. SELECT Category, Color, ItemMaterial, Style, ListPrice Enter conditions: Category=’Ski’ And Style=’Jump’ And ItemMaterial=’Composite’ Run the query to ensure it works Add the conditions for Color=’Yellow’ and ListPrice<300 Test the query Add the conditions for Color=’Red’ and ListPrice<400 Add the correct parentheses Run the query and test it

12 Color Options Yellow and price conditions All 5 conditions must hold, so only one row matches

13 Multiple Conditions (Category=N’Ski’ AND Style=N’Jump’ AND ItemMaterial=N’Composite’) AND ( (Color=‘Yellow’ AND ListPrice<300) OR (Color=‘Red’ AND ListPrice<400) )

14 JOIN Query: Sales Sales in May Cash payment

15 Action Start with a blank query Add SELECT, FROM, WHERE Set SaleID, SaleDate, CustomerID, and PaymentMethod Use only the Sale table Set the SaleDate between 01-May-2004 AND 31-May Set PaymentMethod to Cash Run the query to test it

16 JOIN Tables: Sale + Customer Join condition Additional columns

17 Action Add the Customer table Check the join condition: ON Sale.CustomerID = Customer.CustomerID Add Customer LastName and FirstName to the SELECT statement Run the query to test it

18 JOIN: SQL SELECT SaleID, SaleDate, Sale.CustomerID, LastName, FirstName, PaymentMethod FROM Sale INNER JOIN Customer ON Sale.CustomerID = Customer.CustomerID WHERE SaleDate Between ’01/05/2004' AND '31/05/2004' AND PaymentMethod='Cash'

19 Building a more complex query Which customers bought Atomic skis in January or February? What do you want to see?Customer names, SaleDate What do you know?Manufacturer name, SaleDate range, Category is Ski What tables are involved? How are they joined? Customer … Sale … ItemModel, Manufacturer SELECTLastName, FirstName, SaleDate FROM Customer, …, Sale, …, ItemModel, Manufacturer JOIN WHERE Manufacturer.Name=N‘Atomic”’ AND Sale.SaleDate BETWEEN ’01/01/2004’ AND ’29/02/2004’ AND ItemModel.Category = N‘Ski’

20 Join: Many Tables

21 SQL: Many Table JOINs SELECTLastName, FirstName, powder.ItemModel.Category, Name, SaleDate FROMpowder.Manufacturer INNER JOIN powder.ItemModel ON powder.Manufacturer.ManufacturerID = powder.ItemModel.ManufacturerID INNER JOIN powder.Inventory ON powder.ItemModel.ModelID = powder.Inventory.ModelID INNER JOIN powder.SaleItem ON powder.Inventory.SKU = powder.SaleItem.SKU INNER JOIN powder.Sale ON powder.SaleItem.SaleID = powder.Sale.SaleID INNER JOIN powder.Customer ON powder.Sale.CustomerID = powder.Customer.CustomerID WHERE(powder.ItemModel.Category = N'Ski') AND(Name = N'Atomic') AND(powder.Sale.SaleDate BETWEEN CONVERT(DATETIME, ' :00:00', 102) AND CONVERT(DATETIME, ' :00:00', 102))

22 Older JOIN Method List tables separated by commas Place join condition in the WHERE clause

23 Calculations Calculated column

24 Action Create a new query using only the ItemModel table In the SELECT row, add a new pseudo column to compute ListPrice-Cost As Profit Add the ORDER BY line to sort by Category and List Price descending Run the query

25 Common Functions LowerTo lower case LenLength/number of characters SubstringGet substring LTrim, RTrimRemove leading and trailing spaces UpperTo upper case GetDateCurrent date DateAddAdd a number to a date DateDiffSubtract two dates ConvertHighly detailed formatting Day, Month, Year, DatePartGet parts of a date AbsAbsolute value CosCosine, all common trig functions FloorInteger, drop decimal values RoundRound-off Books Online: Transact-SQL Reference/Functions

26 Format Dates: Convert

27 Add Days and DateAdd SaleDate + one month SaleDate + 30 days

28 Action Create a new query Use only the Sale table SELECT SaleID and SaleDate Add 30 days to the SaleDate to get LateDate Use DateAdd to add one month to the SaleDate to get SaleMonth Run the query

29 Query: Sum Sum function

30 Action Create a new query Add the Sale table SELECT ShipState and SalesTax WHERE ShipState = ‘CA’ Run the query Verify the correct states are displayed Remove ShipState from SELECT SELECT Sum(SalesTax) AS SumOfSalesTax Run the query

31 SQL: Sum SELECT Sum(Sale.SalesTax) AS SumOfSalesTax FROM Sale WHERE Sale.ShipState=‘CA’

32 Query: Group By Group By produces subtotals for all values in the specified column

33 SQL: Group By SELECT ShipState, Sum(SalesTax) AS SumOfSalesTax FROM Sale GROUP BY ShipState;

34 Action Create a new query Use the Sale table Select columns: ShipState and Sum(SalesTax) AS SumOfSalesTax Click the Group By button and set Group By for the SaleState Run the query

35 Total Sales Value in Colorado Multiply on each row and sum across rows

36 CREATE VIEW—Save a Query CREATE VIEW ColoradoSales AS SELECT Sum(QuantitySold*SalePrice) AS SaleTotal FROM Sale INNER JOIN SaleItem ON Sale.SaleID = SaleItem.SaleID WHERE ShipState=’CO’