Download HW#2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Introduction to database using ACCESS
(PART TWO: Working with multiple tables)
We will use following tables to create and explore database in MS ACCESS
Assume two tables:
CITY table with attributes:
 City name (PK)
 City population
 State
Restaurants table with following attributes:




Restaurant name (PK)
Salary
Number of employees
city
Assume following data for CITY table:
City Name
Baltimore
Washington
Annapolis
Arlington
Las Vegas
City population
2800
1200
500
600
2200
State
MD
DC
MD
VA
NV
Assume following data for Restaurant table:
Restaurant
name
kingrus
Thai King
Phillips
Steak house
Cho mein
salary
100
200
300
500
100
No of
employees
50
20
10
50
20
city
washington
baltimore
baltimore
arlington
arlington
Crab house
50
10
baltimore
Start
Open the database you created in tutorial 1, you will see following screen:
Say no and select the open option on the next screen
You will see your database with tables and queries, if you saved any
Open table city and you will see “+” on the side of each record, implying
this is part of one side of a relationship
If you click on + you will see associated records
Query 1: find the names of restaurants in Maryland
Note you need information from both tables state from city table and name
of restaurant from restaurant table
Go to query and design mode
Select both table’s city and restaurant
Select state name and restaurant name
Since there is restriction on state name MD
You will see the output:
Query 2: Give the total of salaries by states:
Logic; we must group by state
Then sum them
Need both tables
Parameter Queries:
Useful when you want to use the SAME query for DIFFERENT criteria
Ex: if you want to find total for different state at different times
Put [which state?] in criteria
When you run the query you will see the following:
You enter the state and it will run the query for that state
Creating Reports:
Reports are used to create summary statistics
Exercise 1: Create report that lists resturants by city
Select report
Select report wizrd
Select table restarant
You will see the following window:
Select all fields
Since we want to group by city select city as grouping option
Say Ok to next screen
Click NEXT, this will ask you if you want ascending or descending sort
Select ascendong on nmaes
Click next on options and finally finish. You will see following report:
Exercise 2: Create a report that lists totals for each city
We already have a query that calculates total by state
Select report new, report wizard, instead of selecting a table this time select
query which calculates totals by state, i.e.,
Which gives the following output:
Say it is query 5
Select this query in report wizard
Select both state and total, keep selecting next until finish and you will see
the following table:
Exercise 3: Create a report by city & restaurant’s total
Save as query 4
Select report wizrd and select query 4
Select name, city and total from query 4
Select city as grouping field
Select ascending on name
Select until finish and you will get sales by city
Exercise 4: group by city and sub total
Easy method
After grouping by city selection, click on grouping option
On the next screen select summary option
Select sum
Select Ok until finish
You will see the desired report
Designer method:
Start with previous report
Open in design mode
Open report footer
In text box type: Total revenue
In the box next to it right click and in property box, select data tab
Type =sum([total]) and running sum over group
Go to format tab and select currency as format
Next you need sub or control totals:
Click on sorting or grouping icon on the tool bar
Click on it ;
Save it. Your report design should look like
And run it. You should see the following report: