Accounting Information Systems: A Business Process Approach Chapter Six: Understanding and Designing Queries and Reports 1 Learning Objective After completing this chapter, you should understand: The need for queries in relational databases Elements of queries (output attributes, criteria, and tables needed Report models (simple lists, grouped detail, grouped summary, and single entity) Event reports, reference listings, and status reports 2 Learning Objective (Continue) After completing this chapter, you should be able to: Design a query to retrieve information from data tables Design the content and organization of a report Design event reports Design reference listings and status reports 3 Exhibits: 6.2, 6.3 Tables: 6.1 - 6.10 4 Exhibit 6.2 Query Design Template Table Table 1 Table 2 Table 3 1. What attributes do users require in the query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? 3. What foreign keys link the information in a table to the primary keys of other tables in the query? 5 Exhibit 6.3 Report Design Template: Content and Organization Title on Report Header Type of Report Source by Table 1. Attributes displayed on report 2a. Attributes not displayed on report, but necessary for a calculation 2b. Criteria for selection of records in table 3. Foreign keys that link this table to the others used in the report (if any) Content Placement Report header Report details*** Order by Report footer For grouped detail reports: Group by Group header Group detail Order detail by roup footer Formulas for calculations: Table 1 Table 2 Table 3 Attribute Names* and Calculations** Used *Enter the attribute name in the row for each section where it is reported. Precede each attribute name with an abbreviation of the source table’s name. **Indicate the label for the calculation in the row for the section where it is to be displayed, and show the formula for the calculation on the bottom row of the template. 6 ***For grouped detail reports, the report details sections consist of data about each group. For such reports, we specify what appears in the report details area by completing the information in the “For grouped detail reports” section of this template. Table 6.1 Summary of ELERBE’s Database Design and Sample Data Design of Tables Table Name Inventory Customer Order Order_Detail Primary Key ISBN Foreign Key Other Attributes Author, Title, Price, Quantity_On_Hand Quantity_Allocated Name, Address, Contact_Pe Order_Date Customer# Order# Customer# (links to Customer Table) Order#, Order# (links to Order Table) Quantity ISBN* ISBN (links to Inventory Table) *compound primary key Inventory Table ISBN 0-256-12596-7 0-127-35124-8 0-135-22456-7 0-146-18976-4 0-145-21687-7 0-235-624-6 Author Barnes Cromwell Cromwell Quantity_ Quantity_ On_Hand Allocated 4,000 300 $65.00 3,500 0 5,000 50 Title Price Introduction to Business $78.35 Building Database Applications Management Information $68.00 Systems Johnson Principles of Accounting $70.00 8,000 Platt Introduction to E-commerce $72.00 5,000 Rosenberg HTML and Javascript Primer $45.00 260 40 6,000 7 0 Table 6.1 Summary of ELERBE’s Database Design and Sample Data (Concluded) Customer Table Customer# Name 3450 Brownsville C.C. 3451 Educate, Inc. 3452 Bunker Hill C.C. Address Contact_Person Phone Brownsville, TX Smith 956-555-0531 Fairhaven, MA Costa 508-888-4531 Bunker Hill, MA LaFrank 617-888-8510 Order_Detail Table Order# ISBN 0100011 0-256-12596-7 0100011 0-146-18976-4 0100012 0-135-22456-7 0100012 0-146-18976-4 0100012 0-145-21687-7 0100013 0-146-18976-4 0100013 0-256-12596-7 Quantity 200 150 50 75 40 35 100 Order Table Order# Order_Date Customer# 0100011 0100012 0100013 05/11/2003 05/15/2003 05/16/2003 3451 3451 3450 8 Table 6.2 Query Design for QUERY A QUERY A: List of all publications by Cromwell Inventory Table 1. What attributes do users require in the query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? ISBN, Author, Title Author=“Cromwell” 9 Table 6.3 Results of Query A ISBN Title Author 0-127-35124-8 0-135-22456-7 Building Database Applications Cromwell Management Information Systems Cromwell Note: For the full Inventory Table, see Table 6.1 on page 244. 10 Table 6.4 Query Design for QUERY B QUERY B: List of all orders on 05/15/2003 Order Table 1. What attributes do users require in the query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? Order#, Order_Date, Customer# Order_Date5#05/15/2003# 11 Table 6.5 Panel A: Query Design for QUERY C The marketing manager wants a report that shows all orders for a book identified as ISBN 0-127-35124-8 during the year 2002. The information needed includes Name, Address, Contact_Person, Phone, and Quantity. Table 1. What attributes do users require in the query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? 3. What foreign keys link the information in a table to the primary keys of other tables in the query? Order Order_Date.#12/31/2001# and Order_Date,#01/01/2003# Order_Detail Customer Quantity Name, Address, Contact_Person, Phone ISBN=0-127-35124-8 Customer# (to identify Order# (to link to the appropriate customer) Order records) 12 Table 6.5 (Continued) Panel B: Query Design for QUERY D The marketing manager wants a report that shows all orders for a book identified as ISBN 0-127-35124-8, regardless of year of order. The information needed includes Name, Address, Contact_Person, Phone, and Quantity. Table 1. What attributes do users require in the Contact_Person, query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? 3. What foreign keys link the information in a table to the primary keys of other tables in the query? Order Order_Detail Customer Quantity Name, Address, Phone ISBN=0-127-35124-8 Customer# (to identify appropriate customer) Order# (to link to the Order records) 13 Table 6.5 (Concluded) Panel C: Query Design for QUERY E The marketing manager wants a report that shows all orders for a book with the title, “Building Database Applications,” during the year 2002. The manager does not know the ISBN for that book. The information needed is Name, Address, Contact_Person, Phone, and Quantity. Table 1. What attributes do users require in the query output? 2. What criteria will be used to generate the output? What attributes will be used in the criteria? 3. What foreign keys link the information in a table to the primary keys of other tables in the query? Order Order_Detail Quantity Order_Date.#12/31/2001# and Order_Date,#01/01/2003# Customer# (to identify appropriate customer) Inventory Customer Name, Address, Contact_Person, Phone Title = “Building Database Applications” Order# (to link to the Order records) ISBN (to link to the Inventory record) 14 Table 6.6 Fairhaven Convenience Store: Tables with Sample Data Manager Table SSN Last_NameFirst_Name Exemptions 105-50-1234 154-08-8304 012-50-1237 023-45-8921 Green Ola Barley Mello Inventory Table Product# Description 101 102 103 Cindy Patrick Thomas Jay Address File_Status Plainville, MI Newport, MI Wareham, MI Paris, MI Single Married Single Married Supplier Reorder_Point Begin_OH Regular gas Engine oil Antifreeze Mobil Dow Shell 50 30 Sale Table Sale# SSN Date Sales_Tax 201 202 203 204 105-50-1234 105-50-1234 154-08-8304 154-08-8304 12/15/03 12/15/03 12/15/03 12/16/03 $0.85 $1.45 $1.00 $0.15 1000 1 3 1 4 10000 100 10 15 Table 6.6 Fairhaven Convenience Store: Tables with Sample Data (Concluded) Sale_Detail Table Sale# Product# Quantity_Sold Price 201 201 202 202 203 204 101 103 101 102 101 102 13 1 14 2 10 1 $2.00 $1.50 $1.50 $3.00 $2.00 $3.00 Deposit Table Deposit# Date Amount 801 12/15/03 $77.80 Note: In the examples in this chapter, we will assume that the quantity on hand is updated only periodically. Thus, the Quantity_On_Hand field in the Inventory Table has been replaced by the Begin_OH field. The Begin_OH represents the quantity on hand at the beginning of the period. 16 Table 6.7 Report Content for the Grouped Detailed Status Report in Figure 6.6A Title on Report Header Type of Report Source by Table 1. Attributes displayed on report 2a. Attributes not displayed on report, but necessary for a calculation 2b. Criteria for selection of records in table 3. Foreign keys that link this table to the others used in the report (if any) Detailed Inventory Status Report Grouped detail status report Sale (S) Sale_Detail (SD) Inventory (I) Date Sale#, Product#, Quantity_Sold Description, Supplier, Begin_OH N/A N/A N/A Product#, Sale# 17 Table 6.8 Report Organization for Grouped Detailed Status Report in Figure 6.6A Attribute Names and Calculations* Used No attributes or calculations See group details I: Product# N/A Content Placement Report header Details Order by Report footer For grouped detail reports: Group by SD: Product# Group header I: Product#, Description, Supplier, Begin_OH Group detail SD: Sale#, Quantity_Sold; S: Date Order detail by SD: Sale# Group footer Current_Quantity_On_Hand* *Formulas for calculations: Current_Quantity_On_Hand = Begin_OH - Sum (Quantity_Sold) I = Inventory Table; SD = Sales_Detail Table; S = Sales Table 18 Table 6.9 Sample Data for H & J Tax Preparation Service Services Table Service# Service_Description Fee Year-to-Date Revenues 1040 Sch-A Sch-B Federal Individual Income Tax Form 1040 (long form) 1040 Schedule A (itemized deductions) 1040 Schedule B (interest & dividend earnings) $ 53,300 1040 Schedule C (sole proprietorship) $ 84,000 State Income Tax Return $ 81,000 Corporate Income Tax $103,000 $100 $50 $120,000 $ 51,000 Sch-C State Corp $50 $110 $80 $30 (per hr.) Client Table Client# Client_Name Address 1001 1002 1003 242 Greene St., St. Louis, MO 314-222-3333 $0 123 Walnut St., St. Louis, MO 314-541-3322 $0 565 Lakeside, St. Louis, MO 314-541-6785 Robert Barton Donna Brown Sue Conrad Telephone Service_Request Table Request# Client# Accountant# 104 105 106 1001 1003 1002 405-60-2234 405-60-2234 512-50-1236 Beg_Bal $0 Date 02/12/03 02/15/03 02/16/03 19 Table 6.9 Sample Data for H & J Tax Preparation Service (Concluded) Accountant Table Accountant# Accountant_ Name 405-60-2234 512-50-1236 Jane Smith Michael Speer Service_Request_Detail Table Request# Service# Fee 104 104 104 104 105 105 106 106 106 106 106 1040 Sch-A Sch-B State 1040 State 1040 Sch-A Sch-B Sch-C State $100 $ 50 $ 50 $ 80 $100 $ 80 $100 $ 50 $ 50 $110 $ 80 Invoice Table Invoice# Request# Invoice_Date Amount 305 306 307 $280 $390 $180 104 106 105 02/13/03 02/22/03 02/23/03 20 Table 6.10 Grouped Detail Status Report Content and Organization Title on Report Header Type of Report Source by Table 1. Attributes displayed on report 2a. Attributes not displayed on report, but necessary for a calculation 2b. Criteria for selection of records in table 3. Foreign keys that link this table to the others used in the report (if any) Detailed Inventory Status Report Grouped detail status report Sale (S) Sale_Detail (SD) Inventory (I) Date Sale#, Quantity_Sold Product#, Description, Supplier, Begin_OH Product# Sale# 21 Table 6.10 Grouped Detail Status Report (Concluded) Content Placement Report header Report details Order by Report footer For grouped detail reports: Group by Group header Group detail Order detail by Group footer Attribute Names and Calculations* Used No attributes or calculations See group details Product# group N/A I: Product# I: Product#, Description, Supplier, Begin_OH SD: Sale#, Quantity_Sold S: Date SD: Sale# Current_Quantity_On_Hand* *Formulas for calculations: Current_Quantity_On_Hand = Begin_OH - Sum (Quantity_Sold) for a particular product 22