Download presentation
Presentation is loading. Please wait.
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. 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: FIDFname F1Chao F2Smith F5Boxer Student File: SIDSname FID S1PeterF1 S2PaulF2 S3SmithF1 Faculty Join Student =
8
Join Example Student File: SIDSname FID S1PeterF1 S2PaulF2 S3SmithF1 StudentCourse File: SIDCID S1ISYS263 S1Acct101 S3ISYS363 S2ISYS263 S2Fin350 S2Acct101 Course File: CIDCname Units ISYS263 IS Intro3 ISYS363 MIS Intro3 Acct101accounting3 Fin350Finance Intro3 (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 Student Account Faculty Course Has 11 Enroll MM Advise M 1 SID Sname Major SID Balance FID Fname CID Cname Units Phone Grade GPA
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
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
15
Order Processing Database
16
Query Examples –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
17
Calculated Fields Rename a field: –NewName:OldName Define a calculated field: –Tax:salary*.15 –Age:Year(Now()) – Year(DOB) –IIF function
18
Sorting One field sorting Two fields sorting
19
Other Queries Update query: –Query tools/Design/Query type/Update Delete query Parameter query CrossTab query –Crosstab row
20
Access Tools for Import/Export Import from Excel: –The first row of Excel’s list should contain field names –External Data/Import/Excel Export to Excel: –External Data/Export/Excel
21
Open Database Connectivity (ODBC) Provide a standard to retrieve data from a database. It manages one or more "database drivers“ that enables the communication between database and applications. To access a database, we use ODBC facilities to define a ODBC data source name for the database.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.