8
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN? INFORMATION INFORMATION

Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Embed Size (px)

Citation preview

Page 1: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Querying a Database

- A question or an inquiry (dictionary.com)

- WHAT ARE WE ASKING QUESTIONS ABOUT?

THE DATATHE DATA

- BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

INFORMATIONINFORMATION

Page 2: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

What do Access queries allow you to do?

1) Display selected fields and records from tables

2) Sort records

3) Perform calculations

4) Generate data for forms, reports and queries

5) Update data in the tables of a database

6) Find and display data from two or more tables

Page 3: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Select Queries- Ask questions of data and retrieve results- Types of results:

- Entire Tables

- Certain Fields

- Data based on criteriaCriteria Meaning

= Equal to (implies exact match)

< , <= Less than / Less than or Equal To

>, >= Greater Than / Greater Than or Equal To

<> Not Equal To

Between…and Between value1 and value2 inclusive

In() In(value1, value2) – contained in the list

Like Matches a pattern

Page 4: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Sorting Data

1) Alphabetically (A to Z) or (Z to A)

2) Numerically (Number or Currency)

3) Chronological Order (Date/Time)

- All data can be sorted either in ascending or descending order

- Sorting can be accomplished through the datasheet view or the query builder screen

- Ability to sort on two or more fields- Primary, Secondary, … sort keys

Page 5: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Conditional Operators

AND- value1 AND value2

- requires that both conditions are met to return a value

OR

- value1 OR value2

- requires that one or the other or both conditions are met to return a value

- DoctorFName = “Luigi” AND DoctorIQ>200

- PatientFName = “Frank” or PatientLName = “Smith”

Page 6: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Calculated Fields

Calculations Meaning

Avg Calculate the average of a column

Count Count the number of records

Max Obtain the Maximum Value of a column

Min Obtain the Minimum Value of a column

Sum Add the contents of a column

User Defined Create a new column based on a math formula

DoctorYearlySalary / 12

DoctorMonthlySalary * 0.07

Page 7: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Lab AssignmentTO DO: Answer the following questions about the data:

1) List all doctors in the system

2) List all patients in the system

3) List all doctors whose last name begins with “A”

4) List all appointments that have occurred in the last week in order of date

5) List all appointments which occur today and show the patient, doctor, and hospital associated with the appointment along with date and time

6) Show the number of appointments that have occurred in the last month

Page 8: Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?

Lab Assignment cont.- Now, assume that we want to keep track of each individual

doctor’s yearly salary. Make the appropriate adjustment to your table and enter in the data.

- Answer the following questions:

- Compile a list of doctors in order of their yearly salary from highest to lowest

- Calculate the average salary for a doctor in our system

- If a doctor gets taxed 11% of his salary per month, calculate the total amount of tax the doctor will pay in one year