Courses/Computer Science/CPSC 203/CPSC 203 Template/Labs Template/Week 3 - Lab 2: Query Analysis Examples (Union Append queries). Review for Assignment 3

From wiki.ucalgary.ca
Jump to: navigation, search

This page is based on the material from here. But, the page has been updated to match the schedule and changes for Fall 2009.

Notes

  • Skills covered in this module:
  1. Create Query Analysis
  • A step by step example of how to properly perform some query analysis on data including some textual analysis.
  • Currently, sample screenshots are provided. Once a copy of Office 2007 is obtained, sample databases will be made, along with their corresponding screenshots.

How to import Excel Data into an Access DB

Basic Notion: The output of one query, is the input for the next query. An analysis is composed of a sequential set of queries (i.e. a “path” in our dots-and-edges language).

Using the spreadsheet data for "What are your five top favorite websites?" survey, you will import the data into Access for further analysis.

Go to the "External Data" tab and then select from the Import section Excel.

Import excel01.png

Then using the wizard select the spreadsheet file and import into a new table

Import excel02.png

The result of that table should look similar to the following image.

Spreadsheet-data.png

Create a separate query for every website rank

  • Using the imported Access table, create five queries for the five different website rankings. This means to create 5 queries as follows: One query will hold the websites that have the rank "Website1", another query will hold the websites that have the rank "Website2", ... etc.
  • Create a query that will organize the information as follows for the websites that have the first rank. In that query, a new field called "WebsiteRank" is added to reflect the rank of the selected websites.

F09 w3 lab2 Fig1.PNG

  • The results of this query should look similar to the one below.

F09 w3 lab2 Fig2.PNG

  • By the end of this section, you should have 5 queries for the five different website rankings similar to the figure below.

F09 w3 lab2 Fig3.PNG

Create a Union Query

  • Using a union query, gather the records from the five separate websites queries into one query.
  • First, you will have to select the five website queries as your data source, and specify that you want to use a union query as shown in the figure below.

F09 w3 lab2 Fig4.PNG

  • For the union query, you need to use an SQL statement as shown below.

F09 w3 lab2 Fig5.PNG

The resulting union query will have the different websites of all the five rankings.

F09 w3 lab2 Fig6.PNG

Create an Append Query

  • The resulting data from the union query needs to be copied to an Access table.
  • To do that, we will create an empty table called WebsiteRankings as shown below.
Website-ranking-table-schema.png
  • Next, we will create an append query that would copy data from the union Query to the WebsiteRankings table. Create the append query as shown below.

Step 1

F09 w3 lab2 Fig8.PNG

Step 2

F09 w3 lab2 Fig7.PNG

  • As you run the append query, the WebsiteRankings table will be automatically populated as follows.

F09 w3 lab2 Fig9.PNG

Analyze the WebsiteRankings Table

  • Extract the website data from the “WebsiteRankings” table, and put into “long” form:

WebsiteRank WebsiteName 1 FaceBook 2 Hotmail 3 …..

… 1 Facebook 2 MSN 3 ….

  • You will create a query that will calculate the website ranking use a custom formula like this one:

IIf([WebsiteRank]="Website1",5,IIf([WebsiteRank]="Website2",4,IIf([WebsiteRAnk]="Website3",3,IIf([WebsiteRank]="Website4",2,1))))

Website-ranking-query02-design.png
Website-ranking-query02-design-result.png
  • Create another query based off this previous query that will do a summation of all the scores for each website.
Sum-query-schema.png
Sum-query-schema-result.png