1 All Powder Board and Ski Microsoft Access Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2007.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Information Systems Technology Ross Malaga B Copyright © 2005 Prentice Hall, Inc. B-1 WORKING WITH DATABASES.
Advanced SQL Topics Edward Wu.
All Powder Board and Ski
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 8: Applications Jerry Post Copyright © 2007.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 6: Forms and Reports Jerry Post Copyright © 2007.
All Powder Board and Ski Microsoft Access Workbook Chapter 3: Database Tables Jerry Post Copyright © 2007.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 10: Database Administration Jerry Post Copyright © 2007.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
BASIC SKILLS AND TOOLS USING ACCESS
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Chapter 40 - Physiology and Pathophysiology of Diuretic Action Copyright © 2013 Elsevier Inc. All rights reserved.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
List and Search Grants Chapter 2. List and Search Grants 2-2 Objectives Understand the option My Grants List Grant Screen Viewing a Grant Understand the.
Multiplying binomials You will have 20 seconds to answer each of the following multiplication problems. If you get hung up, go to the next problem when.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING Think Distributive property backwards Work down, Show all steps ax + ay = a(x + y)
Addition Facts
Report Card P Only 4 files are exported in SAMS, but there are at least 7 tables could be exported in WebSAMS. Report Card P contains 4 functions: Extract,
Excel Lesson 9 Applying Advanced Formats to Worksheets
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Course ILT Working with related tables Unit objectives Use the Lookup Wizard to create a lookup field and a multivalued field Modify lookup field properties.
1 Web-Enabled Decision Support Systems Access Introduction: Touring Access Prof. Name Position (123) University Name.
O X Click on Number next to person for a question.
© S Haughton more than 3?
Benchmark Series Microsoft Excel 2013 Level 2
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Squares and Square Root WALK. Solve each problem REVIEW:
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Event 4: Mental Math 7th/8th grade Math Meet ‘11.
Addition 1’s to 20.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
We will resume in: 25 Minutes.
1 Unit 1 Kinematics Chapter 1 Day
Computer Concepts BASICS 4th Edition
Columbus State Community College
1 All Powder Board and Ski Microsoft Access Workbook Chapter 4: Queries Jerry Post Copyright © 2007.
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.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 7: Integrity and Transactions Jerry Post Copyright © 2003.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 4: Queries Jerry Post Copyright © 2003.
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.
Planning & Creating a Database By Ms. Naira Microsoft Access.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2003.
1 All Powder Board and Ski SQL Server Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2003.
Chapter 6: Forms, Reports and Applications All Powder Board and Ski
Chapter 7: Database Integrity and Transactions
Chapter 2: Database Design All Powder Board and Ski
All Powder Board and Ski
All Powder Board and Ski
Presentation transcript:

1 All Powder Board and Ski Microsoft Access Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2007

2 Primary Tables

3 Find Best Customers: 1 Total sales by customer.

4 Action Create a new query in Design view Tables: Customer, Sale, SaleItem Columns: CustomerID, LastName, FirstName, SalesValue: [QuantitySold]*[SalePrice] Sum the SalesValue, Group By the rest Save query as CustomerSales Create new query in Design view Table: CustomerSales query Columns: SalesValue Set Totals and select Avg Run the query

5 Average Customer Sales SELECT Avg(CustomerSales.SalesValue) AS AvgOfSalesValue FROM CustomerSales; $942.11

6 Action Create a new query in Design view Table: CustomerSales query Columns: LastName, FirstName, SalesValue Criteria for SalesValue (enter in SQL) >(SELECT Avg(SalesValue) FROM CustomerSales)

7 Best Customers SELECT.LastName, FirstName, SalesValue FROM CustomerSales WHERE SalesValue > (Select Avg(SalesValue) FROM CustomerSales) ORDER BY SalesValue DESC;

8 INNER JOIN: Sales and Rentals SELECT Rental.RentDate, Rental.CustomerID, Sale.CustomerID, Sale.SaleDate FROM Rental INNER JOIN Sale ON Rental.CustomerID = Sale.CustomerID;

9 Action Create a new query in Design view Tables: Rental and Sale Columns: RentDate, SaleDate, and CustomerID from both tables. Join the tables on CustomerID Run the query Join the tables on RentDate=SaleDate Run the query

10 Inner Join: Same Customer and Day SELECT Rental.RentDate, Rental.CustomerID, Sale.CustomerID, Sale.SaleDate FROM Rental INNER JOIN Sale ON (Rental.RentDate = Sale.SaleDate) AND (Rental.CustomerID = Sale.CustomerID);

11 Action Create a new query in Design view Tables: Customer, Sale, Rental Columns: LastName, FirstName, and CustomerID from Sale and Rental Delete join from Rental to Customer Add join from Sale to Rental Double click this new join Select option to include all from Sale Run the query

12 LEFT JOIN: Sales + Rental SELECT Customer.LastName, Customer.FirstName, Sale.CustomerID, Rental.CustomerID FROM (Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID) LEFT JOIN Rental ON Sale.CustomerID = Rental.CustomerID; Join Properties: Left Join

13 LEFT JOIN Results Customers who purchased items without renting anything have missing (Null) values for the Rental.CustomerID

14 Action Create a new query in Design view Tables: Customer and Sale Columns: LastName, FirstName, and CustomerID Criteria for CustomerID (use SQL): Not In (SELECT CustomerID FROM Rental) Check the SQL Run the query

15 NOT IN SELECT Customer.LastName, Customer.FirstName, Customer.CustomerID FROM Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID WHERE Customer.CustomerID Not In (SELECT CustomerID FROM Rental) ORDER BY Customer.LastName, Customer.FirstName;

16 Action Create a new query in Design view Table: Inventory Columns: ModelID and QuantityOnHand Sum the QuantityOnHand and sort it in descending order Run the query Save it as ModelsOnHand Create a new table in Design view Columns: CategoryID, CategoryName, LowLimit, HighLimit Save it as SalesCategory Enter data

17 Model Quantity On Hand

18 Categories

19 Action Create a new query in Design view Tables: ModelsOnHand and SalesCategory Columns: ModelID, SumOfQuantityOnHand, CategoryID, and CategoryName In SQL view add the inequality join Run the query

20 Inequality Join SELECT ModelsOnHand.ModelID, ModelsOnHand.SumOfQuantityOnHand, SalesCategory.CategoryID, SalesCategory.CategoryName FROM ModelsOnHand INNER JOIN SalesCategory ON (ModelsOnHand.SumOfQuantityOnHand>=SalesCategory.LowLimit) AND (ModelsOnHand.SumOfQuantityOnHand<SalesCategory.HighLimit); The join cannot be displayed in design view and must be entered by hand in SQL view.

21 Sales Categories

22 Action Create a new query in Design view Tables: Customer and Sale Columns: CustomerID, LastName, FirstName, and SaleDate Set January sale date in criteria row Switch to SQL Copy the entire statement Add the word Union Paste the SELECT statement and change the date condition to March Run the query

23 UNION Query List customers who bought items in January or in March. Note: it could be done with simple conditions, but it is good practice for UNION. SELECT Customer.CustomerID, LastName, FirstName, "Jan" As SaleMonth FROM Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID WHERE (((Sale.SaleDate) Between #1/1/2004# And #1/31/2004#)) UNION SELECT Customer.CustomerID, LastName, FirstName, "Mar" As SaleMonth FROM Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID WHERE (((Sale.SaleDate) Between #3/1/2004# And #3/31/2004#));

24 Action Create a new query in Design view Tables: Rental, RentItem, Inventory, and ItemModel Columns: RentDate, Category, RentFee Set totals to sum RentFee Set Where and criteria for RentDate to Between [Start Date] And [End Date] Run the query

25 Query Parameters

26 Action Create a new query in Design view Do not select any tables Switch to SQL view Enter the CREATE TABLE command Run the query

27 CREATE TABLE Query CREATE TABLE Contacts ( ContactIDLong, ManufacturerIDLong, LastNameText(25), FirstNameText(25), PhoneText(15), Text(120), CONSTRAINT pk_Contacts PRIMARY KEY (ContactID), CONSTRAINT fk_ContactsManufacturer FOREIGN KEY (ManufacturerID) REFERENCES Manufacturer(ManufacturerID) ) ;

28 Create a Temporary Table CREATE TABLE MyTemp ( IDLong, LNameText(25), FNameText(25) );

29 Action Create a new query in Design view Do not select any tables Switch to SQL view Type the INSERT command: INSERT INTO Customer (LastName, FirstName, City, Gender) VALUES ('Jones', 'Jack', 'Nowhere', 'Male'); Run the query

30 INSERT INTO (One Row) INSERT INTO Customer (LastName, FirstName, City, Gender) VALUES ('Jones', 'Jack', 'Nowhere', 'Male');

31 INSERT INTO (Copy Rows) INSERT INTO MyTemp (ID, LName, FName) SELECT CustomerID, LastName, FirstName FROM Customer WHERE City='Sacramento' ;

32 Action Create a new query in Design view Table: ItemModel Columns: Category, ModelYear, and Cost Criteria: Category=Board And ModelYear=2004 Run the query Choose Query/Update Query Under Cost set Update To: Round([Cost]*1.04,2) Run the query

33 UPDATE Board Cost Query / Update Query New value UPDATE ItemModel SET Cost = Round([Cost]*1.04,2) WHERE (Category="Board") AND (ModelYear=2004); Run

34 Action Create a new query in Design view Table: MyTemp Columns: ID, LName, FName Criteria: ID>100 Test the query Choose Query/Delete Query Run the query

35 DELETE Rows DELETE FROM MyTemp WHERE ID > 100;

36 DROP TABLE DROP TABLE MyTemp;