2015-05-13 58 views
-1

解決我被困在4 DML問題從SQL-EX極品sql-ex.ru/ DML EX4

For each group of laptops with the identical model number, add following record into PC table: 
code: minimal code among laptops in the group +20; 
model: laptop's model number +1000; 
speed: maximal speed among laptops in the group; 
ram: maximal ram size among laptops in the group *2 
hd: maximal hd capacity among laptops in the group *2; 
cd: default value; 
price: maximal price among laptops in the group divided by 1.5. 
Remark. Consider model number as numeric. 

架構是

Product(maker, model, type) 
PC(code, model, speed, ram, hd, cd, price) 
Laptop(code, model, speed, ram, hd, screen, price) 
Printer(code, model, color, type, price) 

感謝您的幫助提前

+0

嘗試插入查找與選擇F-或從其他表格中插入數據,並通過聚合(MIN,MAX)分組以獲取您需要插入的數據(https://docs.oracle.com/cd/E17952_01/refman-5.1-en/insert-select.html和http://www.oracle.com/technetwork/issue-archive/2013/13-jan/o13sql-1886636.html) –

回答

0

嘗試此查詢

insert into PC (code,model,speed,ram,hd,price) 
select min(code)+20,model+1000,max(speed),max(ram)*2,max(hd)*2,max(price)/1.5 
from Laptop group by model