assignment2 solution database

8 677 8
assignment2 solution database

Đang tải... (xem toàn văn)

Thông tin tài liệu

Solution to the Assignment Dirk Van Gucht & Mo Zhou September 29, 2008 Relational Algebra - We write r(ABC) for a relational schema with relation name r and attributes (or fields) A, B, and C The underlined attribute is the primary key Basic Algebra Given following relational schema, write expressions of relational algebra to answer the following queries Relational schema of question Product(model, maker, type) PC(model, speed, ram, hd, price) Laptop(model, speed, ram, hd, screen, price) Printer(model, color, type, price) The sample data for relations of question These data are not used to calculate results of following questions Product: model maker 1001 A 3001 B 2001 C type PC Printer laptop PC: model 1001 1002 1003 speed 2.66 1.42 3.20 ram 1024 512 2048 hd 250 250 160 price 2114 955 1049 Laptop: model speed 2001 2.00 2002 1.73 2003 1.83 ram 1024 512 2048 hd 250 80 60 screen 15 24 20 Printer: model color 3001 true false 3002 3003 true type ink-jet laser laser price 99 239 899 price 2114 955 1049 (a) What PC models have a speed of at least 3.00? πmodel (σmodel≥3.00 (P C)) (b) Find the model numbers of all color laser printers πmodel (σtype=laser∧color=true (P rinter)) (c) Which manufacturers make laptops with a hard disk of at least 100GB? πmaker (P roduct σhd≥100 (Laptop)) (d) Find the model number and price of all products (of any type) made by manufacturer B πmodel,price (σmaker=B (P roduct)) (πmodel,price (P C) ∪ πmodel,price (Laptop) ∪ πmodel,price (P rinter)) (e) Find those manufacturers that sell Laptops, but not PC’s πmaker (σtype=Laptop (P roduct)) − πmaker (σtype=P C (P roduct)) (f) Find those manufacturers that sell all models of PCs and lazer Printers πmaker (P roduct/(πmodel (P C) ∪ πmodel (σtype=lazer (P rinter)))) (g) Find those manufacturers whose laptops have all ram sizes that manufacturer B’s laptops have (πmaker,ram (P roduct Laptop)) / (πram (σmaker=B (P roduct) Laptop)) (h) Find those manufacturers of at least two different computers (PC’s or laptops) with speeds of at least 2.80 ρ(T EM P 1, πmodel (σspeed≥2.80 (P C)) ∪ πmodel (σspeed≥2.80 (Laptop))) ρ(T EM P 2, P roduct T EM P 1) πmaker (σT EM P 2.maker=T EM P 3.maker∧T EM P 2.model=T EM P 3.model (T EM P 2× ρ(T EM P 3, T EM P 2))) (i) Find the manufacturers of PC’s with at least two different speeds πR1.maker (σR1.speed=R2.speed∧R1.maker=R2.maker ((ρ(R1, (P roduct P C)) × ρ(R2, (P roduct P C))))) (j) Find the manufacturers who sell exactly two different models of PC πR1.maker (σR1.model=R2.model∧R1.maker=R2.maker (ρ(R1, (P roduct P C)) × ρ(R2, (P roduct P C)))) − πR1.maker (σR1.model=R2.model∧R1.model=R3.model∧R2.model=R3.model ∧R1.maker=R2.maker∧R1.maker=R3.maker (ρ(R1, (P roduct P C)) × ρ(R2, (P roduct P C)) × ρ(R3, (P roduct P C)))) (k) Find those pairs of PC models that have both the same speed and RAM A pair should be listed only once; e.g., list (i, j) but not (j, i) Hint: The model numbers can be compared πP C1.model,P C2.model (σP C1.speed=P C2.speed∧P C1.ram=P C2.ram∧P C1.model>P C2.model (ρ(P C1, P C) × ρ(P C2, P C))) (l) Find the manufacturer(s) of the computer (PC or laptop) with the highest available speed Hint: the highest speed means that it is not smaller than any other speeds If you can find all the speeds which are smaller than some speed, you can solve this problem ρ(Computer, (πmodel,speed (P C) ∪ πmodel,speed (Laptop))) ρ(HighestSpeedM odel, πmodel (Computer) − πmodel (σP 1.speed

Ngày đăng: 21/10/2018, 16:56

Tài liệu cùng người dùng

Tài liệu liên quan