1 / 13

Tutorial 8

Tutorial 8. Advanced Queries. Notes. Switch to new database! Tutorial.08 folder Only Session 8.1 and 8.2. Create a crosstab query.

liuz
Download Presentation

Tutorial 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 8 Advanced Queries

  2. Notes • Switch to new database! • Tutorial.08 folder • Only Session 8.1 and 8.2

  3. Create a crosstab query • A crosstab query performs aggregate function (arithmetic operations) calculations on the values of one database field and displays the results in a spreadsheet format. • Possible functions include • average, count, first field value, last field value, etc. • Crosstab Query Wizard will walk you through creating a crosstab query.

  4. A select query versus a crosstab query This figure shows a Select query and a crosstab query. These two queries are based on the same data. In this case the crosstab query is using the Sum function to summarize the potential income for each country`. However, notice that the crosstab query data is much more summarized than the select query data.

  5. Crosstab query aggregate functions The figure below shows the aggregate functions that can be used in a crosstab query.

  6. The Crosstab Query Wizard steps • Select the table or query upon which you want to create the crosstab query. • Select fields to use as row headings. • Select fields to use as column headings. • Select the field that will be calculated upon and what calculation is to be performed.

  7. The final Crosstab Query Wizard dialog box This figure shows the final Crosstab Query Wizard dialog box where you select the field to be used for the calculation, and which type of calculation to perform.

  8. Other types of queries • Find duplicates • a select query that locates duplicate records in a table or query • Find unmatched • returns a datasheet for all records that do not have a matching record in the related table • Top values • Returns the top number top percentage of records • E.g. top 10 or top 25%

  9. Action queries • Queries that make changes to the data in the underlying table(s). • Action queries can: • Create a new table (make-table query) • Add records to a table (append query) • Delete records from a table (delete query) • Update the data in a table (update query)

  10. Action query considerations • These queries change the underlying tables permanently! Be very careful!!! • Always create a select query to test it out first • You can then view the results and determine if these are the records you want to alter. • When you are sure the query is right, run it as an action query.

  11. Many-to-many Relationships Between Tables • A many-to-many relationship exists between tables when the tables involved have multiple matches in each of the tables. • For example, if you have a table containing student data and another table containing course data, you could say that this is a (M:N) relationship because a student can take many courses and a course can have many students • Many-to-many relationships require a third table that will “link” the two tables together in a one-to-many relationship.

  12. A many-to-many relationship In the figure below, you see an illustration of a many-to-many relationship. Note that the Job table is used to join the Position table and the Student table. The Job table contains a PositionID and a StudentID for each position that a students holds. In this case, a student can have more than one position and a position can be held by more than one student.

  13. A query datasheet for a many-to-many relationship Once you have created the third table (the table that joins the two tables in a many-to-many relationship) you can create a query based on all three tables. The following figure show a query datasheet based on the three tables.

More Related