Presentation is loading. Please wait.

Presentation is loading. Please wait.

Querying Database ISYS 363.

Similar presentations


Presentation on theme: "Querying Database ISYS 363."— Presentation transcript:

1 Querying Database ISYS 363

2 Basic Query Language Operations
Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count Totals and SubTotals GroupBy Calculated fields

3 Selection Selection operation retrieves records that satisfy user’s criteria.

4 Criteria >, >=, <, <=, =, <>
Range: BETWEEN 1/1/03 AND 12/31/03 Wildcard: ? – match any one character “K?NG” * - Match any number of characters “C*”

5 Projection Projection operation defines a vertical subset of a table and retrieves only the specified fields. Example: Customer table: CID, Cname, City, Rating Create a query to show CID, Cname, Rating Create a query to show CID, Cname, City

6 Join The two tables must have common attributes:
Key and foreign key match. Combines two tables to form a new table where records of the two tables are combined if the common attributes have the same value.

7 Join Example Faculty File: FID Fname F1 Chao F2 Smith F5 Boxer
Student File: SID Sname FID S1 Peter F1 S2 Paul F2 S3 Smith F1 Faculty Join Student =

8 Join Example (Student Join StudentCourse) Join Course
StudentCourse File: SID CID S1 ISYS263 S1 Acct101 S3 ISYS363 S2 ISYS263 S2 Fin350 S2 Acct101 Student File: SID Sname FID S1 Peter F1 S2 Paul F2 S3 Smith F1 Course File: CID Cname Units ISYS263 IS Intro 3 ISYS363 MIS Intro 3 Acct101 accounting 3 Fin350 Finance Intro 3 (Student Join StudentCourse) Join Course

9 Aggregate Functions Max, Min, Sum, Count, Avg QueryTools/Totals
Ex. Employee: EmpID,Ename, Sex, Race, Birthdate, Hiredate, Salary How many employees in this company? What is the overall average salary?

10 Aggregates by Group Compute the average salary by race.
Compute the average salary by sex. Compute the average salary by Race and Sex. How many employees in each race group?

11 University Database

12 ERD Notations 1 1 Student Has Account M M M 1 Faculty Course Enroll
Major Sname GPA SID Balance SID 1 1 Student Has Account M M M Enroll Advise Grade 1 Faculty Course Units Phone FID Fname CID Cname

13 Query Examples Q1: Display students’ ID, name and account balance who owe university more than $2000. Q2: Display student’s ID, name and total units. Q3: Find students taking at least 9 units and display their ID, Name and total units. Q4: Display CID, Cname, SID, Sname Q5: Display CID, Cname, number of students in each course. Q6: Display faculty’s name and phone if the faculty advises at least three students.

14 Order Processing Database

15 Query Examples Total sales by product Total amount for each order
Find customers live in San Francisco. Produce a customer report that shows CID, Cname, and Rating. Number of customers in each city City, NumbeOfCustomers Produce a report that shows the number of orders for each customer: CID, Cname, TotalNumberOfOrders Total sales by product Total amount for each order MIS report Criteria applied to subtotal

16 Calculated Fields Rename a field: Define a calculated field:
NewName:OldName Define a calculated field: Tax:salary*.15 Age:Year(Now()) – Year(DOB) IIF function

17 Sorting One field sorting Two fields sorting

18 Other Queries Update query: Delete query Parameter query
Query tools/Design/Query type/Update Delete query Parameter query CrossTab query Crosstab row

19 Top n query: Example Top 3 GPA 1. Sort GPA in descending order 2
Top n query: Example Top 3 GPA 1. Sort GPA in descending order 2. From Query/Design view, click Property Sheet and select Top Value


Download ppt "Querying Database ISYS 363."

Similar presentations


Ads by Google