Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020.

Similar presentations


Presentation on theme: "ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020."— Presentation transcript:

1 ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020

2 Chapter 8 Advanced Structured Query Language (SQL)

3 3 SQL Queries Single table query Multiple table query –Nesting query (subquery) Using IN Using EXISTS –Join Table

4 4 Examples SELECT Order_Num FROM ORDERS WHERE Order_Num IN (SELECT Order_Num FROM ORDER_LINE WHERE Part_Num =1234;

5 5 Examples (Cont’d) SELECT Order_Num FROM ORDERS WHERE EXISTS (SELECT * FROM ORDER_LINE WHERE ORDERS.Order_Num = ORDERLINE.Order_Num AND Part_Num =1234;

6 6 Examples (Cont’d) SELECT S.Last, S.First, C.Last, C.First FROM SALES_REP S, CUSTOMER C WHERE S.Srep_Num = C. Srep_Num

7 7 SQL Exercise Write SQL code that will create the relations shown. Assume the following attribute data types: –Student_ID: integer –Student_Name: 25 characters –Faculty_ID: integer –Faculty_Name: 25 characters –Course_ID: 25 characters –Course_Name: 15 characters –Date_Qualified: date –Section_ID: integer –Semester: 7 characters

8 8 SQL Exercise (Cont’d) STUDENT (Primary key: Student_ID) Student_ ID Student_ Name 38214Letersky 54907Altvater 66324Aiken 70542Marra IS_QUALIFIED (Primary key: Faculty_ID, Course_ID) Faculty_ ID Course_I D Date_ Qualified 2143ISM31129/1988 3467ISM42129/1995 3467ISM49309/1996 4756ISM31139/1991 4756ISM31129/1991

9 9 SQL Exercise (Cont’d) FACULTY (Primary key: Faculty_ID) Faculty_I D Faculty_Name 2143Birkin 3467Berndt 4756Collins SECTION (Primary key: Section_ID) Section_IDCourse_ID 2712ISM3113 2713ISM3113 2714ISM4212 2715ISM4930

10 10 SQL Exercise (Cont’d) COURSE ((Primary key: Course_ID) Course_IDCourse_ Name ISM3113Syst Analysis ISM3112Syst Design ISM4212Database ISM4930Networking IS_REGISTERED (Primary key: Student_ID, Section_ID) Student_I D Section_I D Semester 382142714I - 2001 549072714I - 2001 549072715I - 2001 663242713I - 2001

11 11 SQL Exercise (Cont’d) Write SQL queries to answer the following questions: –Is any instructor qualified to teach ISM 3113 and not qualified to teach ISM 4930? –How many students are enrolled in section 2714 during semester I – 2001? –Display all the courses (Course_Name) for which Professor Berndt has been qualified. – Which students were not enrolled in any courses during semester I – 2001?

12 12 Exercise Write SQL codes to create the following tables Customer_ ID Customer_N ame CityState 1Value Furniture PlanoTX 2Home furnishings AlbanyNY 3Eastern Furniture CarteretNJ 4Furniture Gallery PlanoTX CUSTOMER Order_IDProduct_IDQuan 100112 22 100235 100333 ORDER_LINE

13 13 Exercise (Cont’d) Order_IDOrder_DateCustomer_ID 100121-Oct-20001 100221-Oct-20004 100322-Oct-20002 ORDER PRODUCT Product_IDDescriptionProduct_finishStandard_price 1End TableCherry175 2Coffee TableNatural Ash200 3Computer DeskNatural Ash375

14 14 Exercise (Cont’d) Use SQL to design the following queries: –How many different items were ordered on order number 1001? –List product ID and standard price for all desks and all tables that cost more than $200. –What furniture is not made of cherry?

15 15 Exercise (Cont’d) Use SQL to design the following queries: –List all the customers who live in FL, TX and CA. –Find only states with more than one customer. –What are order numbers that have included furniture finished in natural Ash. –What are the names of all customers who have placed orders?

16 16 Exercise (Cont’d) Use SQL to design the following queries: –For each customer who has placed an order, what is the customer’s name and order number? –Which customers have not placed any orders for computer desk? –List the product name and price with the highest standard price.


Download ppt "ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020."

Similar presentations


Ads by Google