33
Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007 1 R. Kornak, AIT Training, July 2009

Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Embed Size (px)

Citation preview

Page 1: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Today’s Goals• Answer questions about homework and lecture 2• Understand what a query is• Understand how to create simple queries using

Microsoft Access 2007

1R. Kornak, AIT Training, July 2009

Page 2: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Review

Topic 1

2R. Kornak, AIT Training, July 2009

Page 3: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

IFRI Data Workflow1. Record Field

Data on Paper Forms

3. Manage Data, Create Queries, and Perform Simple Analysis Using Microsoft Access

2. Enter Data Using IFRI Data Entry Application

4. Export Data for Advanced Analysis and Visualization Using Other Software (e.g. Excel, SPSS, STATA, GIS)

3R. Kornak, AIT Training, July 2009

Page 4: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Review

• The IFRI database has 24 tables that are linked together based on their relationships

• Most forms correspond with one table

• One row for each instance of a form

• Column names used in the database are found in the IFRI manual in <> after each question

• Each column can only have one data type4

R. Kornak, AIT Training, July 2009

Page 5: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Review

• Coded values are used to represent multiple choice answers

• The codes used in the database are shown in ( ) with each question in the IFRI Manual

• You can use Microsoft Access to explore your data using the sort and filter tools

5R. Kornak, AIT Training, July 2009

Page 6: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Introduction to Database Queries

Topic 2

6R. Kornak, AIT Training, July 2009

Page 7: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

What is a Database Query?

• A way to create subsets of the full IFRI database that address a particular research question

• The result of a query is a table showing only the data you are interested in at a given time

• Allows you to combine data from multiple forms and sites

7R. Kornak, AIT Training, July 2009

Page 8: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Database Queries

• Your results can be explored in Access or exported to another program such as SPSS, Excel, or GIS

• Queries can be saved and/or modified for future use– Provides a record of your calculations if you

need to redo them or document them for a paper

8R. Kornak, AIT Training, July 2009

Page 9: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Queries Tools in Access 2007

• We will use the “Design View tool” to create queries in this class

• This tool allows us to add tables to a workspace and specify fields from each one that we are interested in

• Similar to a table, you can view your query in design view or data sheet view

9R. Kornak, AIT Training, July 2009

Page 10: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Software Demonstration• Description of tools on the create tab

of the ribbon

• Adding a table to a query

• Explore your query in design view and data sheet view

• The “run” button runs your query

10R. Kornak, AIT Training, July 2009

Page 11: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Queries in Access 2007

• There are tools to specify how the results should be sorted and filtered using one or more variables

• Similar to the “filter” tool we talked about yesterday except you can use multiple variables at the same time

11R. Kornak, AIT Training, July 2009

Page 12: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Software Demonstration

12R. Kornak, AIT Training, July 2009

Page 13: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Types of Queries

• There are many different types of queries in Microsoft Access

• Today we are only going to talk about 3 types– Select Queries– Make Table Queries– Summary Queries

13R. Kornak, AIT Training, July 2009

Page 14: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Select Queries

• Allow you to select only the variables you are interested in

• A select query does NOT make a copy of your data tables

14R. Kornak, AIT Training, July 2009

Page 15: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Select Queries

• The data shown in your results will automatically update if you make changes to your master data tables

• Data in your master tables will automatically update if you make changes in your results table

15R. Kornak, AIT Training, July 2009

Page 16: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Software Demonstration

• Let’s practice by creating a very simple select query using only the OVERSITE table

• Make a change in either your master table or results table and see how they both update

• Save the query for later use

16R. Kornak, AIT Training, July 2009

Page 17: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Make Table Queries

• Allow you to select only the variables you are interested in and create a new table from them

• A make table query makes a copy of your data and adds it to a new table

17R. Kornak, AIT Training, July 2009

Page 18: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Make Table Queries

• The data shown in your results will NOT automatically update if you make changes to your master data tables

• Data in your master tables will NOT automatically update if you make changes in your results table

18R. Kornak, AIT Training, July 2009

Page 19: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Software Demonstration

• Let’s practice by opening the select query we just made and changing it to a make table query

• Specify a name for your new table and run the query

• Make a change in either your master table or results table and see how they both DO NOT update

• Save the query for later use19R. Kornak, AIT Training, July

2009

Page 20: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Summary Queries• Allow you to create summary statistics

about one or more tables

• Count– e.g. find number of plots per forest or plots

per site

• Average, Total (Sum), Minimum, Maximum, Standard Deviation, Variance– e.g. find the average tree height per plot

• Summary queries can be saved as either make table or select queries 20

R. Kornak, AIT Training, July 2009

Page 21: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Summary Queries• Summary queries are very helpful when you

first begin exploring your data• Similar to the filter tool except you can count

how many of each value occur in your data (histogram)

• You can easily create histograms for each variable to see if there are any significant patterns

• You can easily identify and correct missing or incorrect data

21R. Kornak, AIT Training, July

2009

Page 22: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Software Demonstration

• Let’s practice by opening the make table query we just finished

• We will make a few small changes to it to create a summary query

22R. Kornak, AIT Training, July 2009

Page 23: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 1

• Create a select by query with only the following variables– FNAME– FSIZE– FTOPOGRAPH– FSTEEP

• Save the query as “Select_Forest”

23R. Kornak, AIT Training, July 2009

Page 24: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 2

• Using the query “Select_Forest” answer the following questions:

• Which of the variables are coded values and which are measured values?

• How big is the Khog Bung Preu Forest?

• How many forests are “primarily steep”?

• What does the value “0” mean in the FSTEEP column?

24R. Kornak, AIT Training, July 2009

Page 25: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 3

• Create a make table query with only the following variables– FK_FOREST– PPIN– PSTEEP

• Save the query as “MakeTable_Plot”

• Run the query and save the table as “Plot_results”

25R. Kornak, AIT Training, July 2009

Page 26: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 4

• Using the table “Plot_results” answer the following questions:– What are the units of PSTEEP?– How many plots are in the table?– How many plots are missing data (value of 0) in

the PSTEEP field?– What is the maximum steepness? (hint – use the

sort tool)– How many plots have a value of 5 for

“FK_FOREST? (hint – use the filter tool)26

R. Kornak, AIT Training, July 2009

Page 27: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 5

• Create a new table using a make table query with the following fields:– SNAME– SMARKET– SINDPOP

• Run the query and save the table as “Settlement_Sample”

27R. Kornak, AIT Training, July 2009

Page 28: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 6

• What do each of the fields mean in the “Settlement_Sample” table?

• What data type is each field?

• What are the units of SMARKET?

28R. Kornak, AIT Training, July 2009

Page 29: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 7• Add the “Settlement_sample” table to a new

query• Select the totals icon and make your query

match the one below

29R. Kornak, AIT Training, July

2009

Page 30: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 8

• Run the query (you may need to rename the table or change it to a select query)

• What is the average distance to market?

• What does the “count” statistic mean?

30R. Kornak, AIT Training, July 2009

Page 31: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 9

• Add the PRODUCT table to a new query

• Select the totals icon

• Add the “RNAME” field to your query 2 times

• Under the “Total Option” choose “Group By” for the first RNAME and “Count” for the second RNAME

31R. Kornak, AIT Training, July 2009

Page 32: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

32R. Kornak, AIT Training, July 2009

Page 33: Today’s Goals Answer questions about homework and lecture 2 Understand what a query is Understand how to create simple queries using Microsoft Access 2007

Homework 10

• You just created a histogram of product types

• How many unique products are in the table?

• What are the 3 most common products?

33R. Kornak, AIT Training, July 2009