Graphical Interface for Queries

Slides:



Advertisements
Similar presentations
Concepts of Database Management Seventh Edition
Advertisements

Concepts of Database Management Sixth Edition
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Microsoft Office 2007 Access Chapter 2 Querying a Database.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Querying a Database Microsoft Office Access 2003.
Concepts of Database Management Sixth Edition
Advanced Tables Lesson 9. Objectives Creating a Custom Table When a table template doesn’t suit your needs, you can create a custom table in Design view.
Introduction to Access By Mary Ann Chaney and Alicia Harkleroad.
Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall1 Exploring Microsoft Office Access Committed to Shaping the Next Generation.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 4 BACKNEXTEND 4-1 LINKS TO OBJECTIVES Query Design Query Criteria Modify a Query Using OR.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Access 2003 Lab 3 Analyzing Data and Creating Reports.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
Microsoft Access 2010 Building and Using Queries.
Analyzing Data For Effective Decision Making Chapter 3.
Microsoft Access 2000 Presentation 2 Creating Databases Part I (Creating Tables)
Microsoft Office 2007 Access Chapter 2 Querying a Database.
Concepts of Database Management Seventh Edition
Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! With Microsoft ® Office 2007 Intermediate Chapter.
Concepts of Database Management Seventh Edition
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T7 PROBLEM SOLVING USING ACCESS.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
T7-1 LEARNING OUTCOMES – ACCESS PROBLEM SOLVING 1.Describe the process of using the Simple Query Wizard using Access 2.Describe the process of using the.
XP New Perspectives on Microsoft Access 2002 Tutorial 31 Microsoft Access 2002 Tutorial 3 – Querying a Database.
DAY 18: MICROSOFT ACCESS – CHAPTER 3 CONTD. Akhila Kondai October 21, 2013.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
Copyright © 2016 Pearson Canada Inc.
Working with Data Blocks and Frames
Microsoft Office Access 2010 Lab 3
Spreadsheet – Microsoft Excel 2010
GO! with Microsoft Office 2016
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
Microsoft Office Illustrated Introductory, Windows Vista Edition
Practical Office 2007 Chapter 10
Access Chapter 2 Querying a Database.
Plug-In T7: Problem Solving Using Access 2007
Larry Reaves October 9, 2013 Day 16: Access Chapter 2 Larry Reaves October 9, 2013.
GO! with Microsoft Access 2016
Computer Fundamentals
Microsoft Access 2003 Illustrated Complete
Building and Using Queries
Database Applications – Microsoft Access
Microsoft Office Access 2003
GO! with Microsoft® Access e
Database Queries.
MODULE 7 Microsoft Access 2010
Tutorial 3 – Querying a Database
GROUP BY & Subset Data Analysis
Types of Joins Farrokh Alemi, Ph.D.
Access Lesson 2 Creating a Database
Sirena Hardy HRMS Trainer
Microsoft Office Access 2003
Microsoft Official Academic Course, Access 2016
Nagendra Vemulapalli Access chapters 3&5 Nagendra Vemulapalli 1/18/2019.
Access: Queries III Participation Project
Spreadsheets, Modelling & Databases
Microsoft Office Illustrated Introductory, Windows XP Edition
Shelly Cashman: Microsoft Access 2016
Lesson 13 Working with Tables
Assignment 3 Querying and Maintaining a Database
New Perspectives on Microsoft
Presentation transcript:

Graphical Interface for Queries Farrokh Alemi, Ph.D. Narrated by Vikas Arya Welcome. This is the lecture on queries as part of the course on healthcare databases.

Objectives To develop queries and select subsets of data from a table Also see “Teaching yourself Visually Access 2003” pages 192 through 226 The objective of this section is to introduce you to making queries on databases. In particular, we want you to be able to select subsets of data through using various methods of filtering the content of a table. This lecture corresponds to pages 192 through 226 in assigned book titled “Teaching yourself Visually Access 2003.”

Standard Query Language SELECT Claims.PatientID, Last(ICD9.ICDDescription) AS LastOfICDDescription FROM Claims INNER JOIN ICD9 ON Claims.DiagnosisCode = ICD9.ICD9Codes WHERE (((ICD9.ICDDescription) Like "*diabete*")) GROUP BY Claims.PatientID ORDER BY Claims.PatientID; The standard query language, or SQL, is the way most database managers use to manipulate data in a database. Here you see an example of this language. In a typical SQL command, the analyst specifies the tables from which the data should be read, the way tables should be related to each other (joined together), how the data should be manipulated or filtered and what should be displayed. Later we will cover SQL commands but for this lecture we prefer to start with graphic interfaces that students can use to generate SQL commands to databases. Such graphic databases allow you to point and click to create a query.

A Graphic View This is Microsoft Access’s view for generating a query. You find this query window by opening a database and select the option to design view of the query. You can go back and forth between the graphical and SQL view of the query by clicking on the View button in lower left toolbar.

Toolbars The top part is called the tool bar. There are many database options here. The first row is focused on database options, like opening a database. The second row shows the query toolbar, displayed here in graphical icons. On the left lower corner you see a button that allows you to see various views of a query. For example, you can see an SQL view of the query. Next to it you see the icon for saving the changes you have made to query. To the right of save, you see the option to search as well as a series of typical options available in any software such as print, copy, cut, paste, undo and redo. To the right of redo you see the option of setting type of query and next to it the exclamation mark is for running a query. Next to run option you see the button for showing tables on which the query is run. Obviously you must specify which of the many tables in your database are involved in the query. To the right, you see the Total button shown as a summation sign. This sets the option for summarizing several rows of data into one row, for example, when you sum the data in several rows to show as one value. To the right of the total button, you see a command to restrict how much of the output of the query should be displayed. For example, if you want only the first few rows of the query results displayed, you can do so using this option. Still further to the right is the option query properties, for example, here you can specify that values used should be unique and non-duplicating. Still to the right of this you see a wand. This allows you to use internal Access functions to calculate a new field from existing fields in the tables. To the right of the wand you see the option to return to the database view, so you can go back and forth between query window and database window. To the right of this feature you see the new object icon, where you can automatically generate reports from a query that you have created.

Place to Show Tables Right below the tool bar, you see an area where the tables involved in the query and their relationships can be displayed. You might use this area to specify several tables and set the keys that these tables share and whether the shared key must be present in all tables or a subset of tables. More on this later.

Place to Specify Fields At the bottom of the window, you can see the space for entering the various fields we would like to display in the query. Some of these fields may come from different existing tables. Others may be calculated. For each field listed we need to specify where it comes from. If it comes from a table, in the second row we specify the table. We can also specify whether the field should be used to sort the data in the query display. In the fourth row we have the option of showing the field or hiding it from the display. The last two rows are for criteria that can be used for filtering the field.

Including Relevant Tables in the Query The first step in constructing a query is to include all relevant tables. If a field is used in a query, a table containing the field must be included in the query. This is done through show table icon, which opens a list of queries and tables that one can include. If more than one table is included, one must also specify the relationship between the tables. The relationship between the tables is specified by draging one field from one table on top of another field in another table. This leads to a join between the tables where the content of the two tables are joined together in a separate table if and only if the two fields match each other. For example, one could use patient’s ID in the claims table to join it to the primary key of the patient’s table. Or one could use the diagnosis code in the claims table to a table describing the code.

A query can have as its input another query Several Queries A query can have as its input another query You can set up several queries, one feeding to another. In this fashion, you can do several operations on the data sequentially. For example, one query can count how many cases you have and the next query can use this information to calculate a percent in each record.

Including Appropriate Fields Fields can be included from all joined tables. In this fashion, a select query makes information in various tables available in one setting. Fields can be dragged from the shown tables to the field cell or one can click on the right of field cell and select a field.

Computing a New Field A new field can be calculated from one or more fields in the joined tables or queries. The easiest way for doing so is to put the cursor into the cell for fields, then click on the expression builder icon, the wand. A new window opens that allows you to type the name of the new field followed by colon and followed by the expression to be used to calculate the field. The new name should not contain space or if it does have space it should be put inside brackets. The expression could be composed of built in functions available in Access. Under functions, you will see many examples of existing built in function. The most commonly used function is iif, which allows one to assign a value if a test is met and otherwise assign a different value. There are also numerous functions for dates, the most used one is for calculating difference between two dates.

Examples of Calculations of New Fields Diagnosis: iif(ICD9!Description like “*diabetes*”, “Diabetes”, “Other) If the field Description in the table ICD9 contains the word diabetes assign diagnosis the value “Diabetes” otherwise assign diagnosis the value “Other.” DayTillNow: Date()-Claims!Date Set the field DaysTillNow to be equal to the number of days of difference between today and the field called Date in the table called Claims. The command Diagnosis colon iif open paranthesis ICD9 exclamation mark Description like quote star diabetes star quote comma quote Diabetes quote comma quote Other quote end parenthesis has the following meaning. If the field Description in the table ICD9 contains the word diabetes assign diagnosis the value “Diabetes” otherwise assign diagnosis the value “Other.” DayTillNow: Date()-Claims!Date Set the field DaysTillNow to be equal to the number of days of difference between today and the field date in table Claims.

Types of Queries There are six different types of queries allowed in Access. The most widely used query is Select query, where a criteria is used to select and display a subset of one or more tables. The crosstab table is used to table with one field as the rows in the table and another field as the columns in the table. Usually the cell values in a crosstab query is the count of a third field. Besides these two types of queries there are also a number of queries that lead to direct actions on the tables, these are make, update, append and delete queries that do the actions their names implies on a table. The option to change a query type is available on the query toolbar and can be reached by right clicking on the show tables area.

Purpose of Select Query Show only rows that meet criteria In the select query, the rows in a table are reduced to the rows that meet a set of criteria. For example, we might have a table of claims and want to restrict it to patients who had a claim of influenza. Microsoft Access allows several methods for selecting a subset of a table. One way is to restrict it to the cases that match a key in another field. This is typically done when setting the relationship among tables. Another way is to restrict the content by criteria that a field should meet before it is allowed to be included in the display.

Selecting through Types of Joins First, you need to show the tables that are used in the query using the show table icon. Once the tables have been added to the show table area of the query, then you can set the relationship among the table by setting different types of joins. There are three different joins. The typical join is when the fields in both tables have to be exactly the same before the content of the tables are joined together. The other two allows the field in one table to be always included and the field from the other table included only when it matches. When it does not match the record is still kept but there will be a null value in place of the missing match. For example, one might have a table claims that contains diagnosis codes. The meaning of these diagnostic codes might be available in a separate table called diagnosis codes. A join can select the text for the diagnostic code and combine it with the claim data. A one to one join will lead to listing of all claims in which the diagnostic code has a corresponding text in diagnosis table. In a one to one join in which values of diagnosis code should be matched exactly in both tables, If the diagnosis code is missing in the diagnosis code table, then all corresponding claims will not show. In a one to many, we can display all claims and their corresponding diagnosis. Where the diagnosis code is missing in the diagnosis code table, a missing value is entered.

Select by Criteria You can specify criteria for a field by enter an expression in the Criteria cell for that field. An expression calculates a single value from a combination of fields using mathematical operations, word operations, or logical tests. In this example, the diagnosis descriptions is restricted by the criteria that it should contain the word diabetes. Like is one of the built in functions available through Access. The like function is followed by quotes that contain star or question mark. A star means any number of letters and question mark means 1 additional letter. A star before and after a word means that any word can follow or preceded the target word. In here a sentence such as diabetes meleitus is matched because it contains the word diabetes and is followed by other words. The sentence Severe Diabetes is also matched because a word precedes diabetes. None of these two sentences are exact match to the word diabetes as they contain other words. If we had asked for an exact match there would have been zero records selected.

Using Expressions in Criteria To set up a criterion, you put your cursor inside the cell and click on the expression builder icon, the wand. You can now use any combination of field names from tables and queries that have been included in the query. There are a number of built in functions available. These include the function iif for testing an expression and various functions for dates.

Examples of Criteria Criteria Meaning >120 Greater than 120 Is null No data in the field > 6/12/05 Passed June 12th 2005 Not diabetes Not matching diabetes Not “*lost” Not any text ending with the word lost Like dia* Any text that starts with dia <Date() Before today’s date Between A and D Text starting with A, B and C

Summarizing Several Records You can summarizes several records into one value by using built in functions such as group by, where all records having the same value will be grouped into one, average where in all records in the group are averaged or standard deviation where in the standard deviation of all records in the same group are calculated. A common function is count where all values in the group are counted and the count is entered. Max and min functions will list the maximum and minimum value for the field in the group. In addition, you can use non-mathematical functions such as last or first to select the last or first value in the field in the group. This feature is added to a query by selecting the icon that looks like a summation sign. When you do so, a row is added to the fields area called “total”. IN this row you have to select which of the many features you want to use. In the example shown, the records are grouped by patient ID by entering under the field PatientID the total function Group BY. The last diagnosis listed in the group is selected. This is shown by the fact that we have entered the function last in the total row under the ICDDescription field. If you need to select a subset of the query, you can use the function Where in the total row. You see this under the field ICDDescription. This field is entered twice in the query because the Where function cannot be displayed in the query. Please note that the Where function is executed before the group function is executed. Thus if a patient has three diagnosis, two of which are diabetes related and one of which is not, the group by will select 3 records without the where function and select 2 records with the where function.

Run a Query Once you have organized your query you can select the exclamation icon to run the query. You can also run a query by selecting from the view option at the lower left corner of the toolbar the tabular view of the query.

Other Types of Queries Crosstab Action queries Crosstab query creates a table view of the two fields in the query Action queries make a table, delete selected records, or append selected records to a table.

Purpose of Crosstab Query Organize summary data into tabular format A crosstab query takes the data from different columns of the table and organizes a summary of them into a table. Here the billing data is broken into two groups, less than one thousand and more than one thousand. The diagnosis are broken into diabetes and other diseases, We count the number of patients that fall into every cell.

Crosstab Query A crosstab query allows us to classify records based on content of two fields. To start with, each field should be summarized using group by command. You can create a crosstab by deciding which field will be the row heading, which field you want to be the column heading and which field do you want to summarize in the cells inside the crosstab table you are producing. Again keep in mind that you should use a function to summarize the content of records picked up for the cell values. For example, you can select as row headings the gender of the patients and as column headings their age calculated in decades. For the cell content you may select count of records. Thus you will have a count of patients in each cell. Keep in mind that only one field can be used for column heading while several fields can be used for row headings.

Change Display of Query Results You can change the display of query results in several ways. You can sort the display by using the sort row in the lower part of the query design window. You can also select a field by clicking on the bar right above it and drag it to a different position in order to change the order of fields being displayed. Finally you can rename a field by typing before its name a new name followed by colon. You can change the number of decimals displayed in a calculated field by using the Round function in the calculation. But you cannot change how numbers or dates are displayed in the query without change their format in the original table.

Graphical view of query makes it simple You can only learn using queries by doing many of them This ends our brief introduction of Microsoft Access graphical interface for creating a query. A lot is left unsaid. There many functions that you can use. You can only learn the various features by looking at some of the videos we have prepared for you and by doing many queries yourself. Practice makes perfect. The take home lesson in this lecture is that many features are available and that you can do best by starting to use some of them.