Академический Документы
Профессиональный Документы
Культура Документы
(Bno, Street, Area, City, Pcode, Tel_No, Fax_No) (Sno, FName, LName, Address, Tel_No, Position, Sex, DOB, Salary, NIN, Bno) (Pno, Street, Area, City, Pcode, Type, Rooms, Rent, Ono, Sno, Bno) (Rno, FName, LName, Address, Tel_No, Pref_Type, Max_Rent) (Ono, FName, LName, Address, Tel_No) (Rno, Pno, Date, Comment) Area Sidcup Dyce Partick Leigh City London Aberdeen Glasgow Bristol London Pcode SW1 4EH AB2 3SU G11 9QX BS99 1NZ NW10 6EU Tel_No 0171-886-1212 01224-67125 0141-339-2178 011-916-01170 0181-963-1030 Fax_No 0171-886-1214 1224-671111 0141-339-4439 0117-776-1114 0181-453-7992
PROPERTY_FOR_RENT Pno Street PA14 16 Holhead PL94 6 Argyll St PG4 6 Lawrence St PG36 2 Manor Rd PG21 18 Dale Rd PG16 5 Novar Dr RENTER Rno FName CR76 John CR56 Aline CR74 Mike CR62 Mary OWNER Ono CO46 CO87 CO40 CO93 FName Joe Carol Tina Tony LName Kay Stewart Ritchie Tregear LName Kay Stewart Ritchie Tregear
Pcode AB7 5SU NW2 G11 9QX G32 4QX G12 G12 9AX
Rooms 6 4 3 3 5 4
Ono CO46 CO87 CO40 CO93 CO87 CO93 Pref_Type Flat Flat House Flat
Bno B7 B5 B3 B3 B3 B3
Address 56 High St, Putney, London SW1 4EH 64 Fern Dr, Pollock, Glasgow G42 0BL 18 Tain St, Gourock PA1G 1YQ 5 Tarbot Rd, Kildary, Aberdeen AB9 3ST Address 2 Fergus Dr, Banchory, Aberdeen AB2 7SX 6 Achray St, Glasgow G32 9DX 63 Well St, Shawlands, Glasgow G42 12 Park Pl, Hillhead, Glasgow G4 0QR Comment Too small Too remote No dining room
Tel_No 0171-774-5632 0141-848-1825 0147-392178 01224-196720 Tel_No 01224-861212 0141-357-7419 0141-943-1728 0141-225-7025
VIEWING Rno Pno CR56 PA14 CR76 PG4 CR56 PG4 CR62 PA14
Avg 17000
Sum 54000
B5 B7 SQL:
2 1
39000 9000
Exercise #15 Read the tables: For each branch office with more than 1 staff member, find the number of staff working in each branch and the total of their salaries. Write the SQL to produce the equivalent resulting table. Answer: Result Table: Bno Count B3 3 B5 2 SQL:
Exercise #16 Read the tables: Using a subquery, list the staff (number, name, position) who work in the branch at 163 Main St. Write the SQL to produce the equivalent resulting table. Answer: Result Table: Sno FName SG37 Ann SG14 David SG5 Susan SQL: Exercise #17 Read the tables: List the staff (number, name, position, salary) whose salary is greater than the average salary. Write the SQL to produce the equivalent resulting table.
Answer: Result Table: Sno FName SL21 John SG14 David SG5 Susan
SQL: Exercise #18 Read the tables: List the names of all renters who have viewed a property along with any comment supplied. Write the SQL to produce the equivalent resulting table. Answer: Result Table: Rno FName CR56 Aline CR56 Aline CR56 Aline CR62 Mary CR76 John SQL: Exercise #19 Read the tables: For each branch office, list the names of the staff who manage properties and the properties they manage. Order appropriately. Write the SQL to produce the equivalent resulting table. Answer: Result Table: Bno Sno B3 SG14 B3 SG14 B3 SG37 B3 SG37 B5 SL41 B7 SA9 SQL:
Exercise #20 Read the tables: For each branch, list the staff who manage properties, including the city in which the branch is located and the properties they manage. Write the SQL to produce the equivalent resulting table. Answer: Result Table: Bno City B3 Glasgow B3 Glasgow B3 Glasgow B3 Glasgow B5 London B7 Glasgow SQL: