Presentation is loading. Please wait.

Presentation is loading. Please wait.

Querying Database. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy Calculated.

Similar presentations


Presentation on theme: "Querying Database. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy Calculated."— Presentation transcript:

1 Querying Database

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 Projection Projection operation defines a vertical subset of a table and retrieves only the specified fields.

5 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.

6 Example Faculty File: FIDFname F1Chao F2Smith Student File: SIDSname FID S1PeterF1 S2PaulF2 S3SmithF1 Faculty Join Student =

7 Aggregate Functions Max, Min, Sum, Count, Avg Ex. Student: SID,Sname, GPA, Sex, Major –How many students in this University? –What is the overall average GPA?

8 Aggregates by Group –How many students in each major? –Compare male students and female students average GPA.

9 Examples Customer: CID, Cname, City, Rating Orders: OID, Odate, SalesPerson, CID Queries: –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 total number of orders for each customer: CID, Cname, TotalNumberOfOrders

10 Access Query Demo Select fields Rename a field: –NewName:OldName Define a calculated field: –Tax:salary*.15 –Age:Year(Now()) – Year(DOB) –IIF function

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

12 Complex condition Rating = “A” OR Rating = “B” Cname = “Chao” OR Cname = “Smith” Rating = “A” OR Rating = “B” AND City=“SF” (Rating = “A” OR Rating = “B”) AND City=“SF”

13 Sorting One field sorting Two fields sorting

14 Total and Subtotal View/Totals –GroupBY –Other functions Examples: –Total number of customers –Number of customers in each city City, NumbeOfCustomers

15 Join Customer Join Orders Example: –Produce a report that shows the total number of orders for each customer: CID, Cname, TotalNumberOfOrders

16 Other Queries Update query Delete query Parameter query CrossTab query

17 Other Tools File/Get External Data File/Export

18 Comparsion between Excel and Access

19 Excel’s Database Tools Data –Sort –Filter –Subtotals –Pivot table/Pivot chart OLAP: On Line Analytical Process –Import external data Import data New web query New database query

20 Word’s Database Tools Tools/Letter and Mailing –Mail merge


Download ppt "Querying Database. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy Calculated."

Similar presentations


Ads by Google