资源描述:
《SQL语句上机题》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、习题6.1.3:使用习题5.2.1中提供的数据库模式用SQL语句写出后面的查询,并使用习题5.2.1提供的资料写出查询结果。Product(marker,model,type)PC(model,speed,ram,hd,rd,price)Laptop(model,speed,ram,hd,screen,price)Printer(model,color,type,price)*a)找出所有价格在$1200以下的PC机的型号、速度和硬盘大小。Selectmodel,speed,hdFrompcWherepiece<1
2、200*b)要求同(a),但是重命名列speed为megahertz以及列hd为gigabytes。selectmodel,speedasmegahertz,hdasgigabytesfrompcwhereprice<1200c)找出所有打印机制造厂商。selectdistinctmakerfromproductwheretype=’printer’d)找出价格在$2000以上的手提电脑的型号、内存大小和屏幕尺寸。selectmodel,ram,screenfromlaptopwhereprice>2000*e)找
3、出关系Printer中所有彩色打印机元组,注意属性color是一个布尔类型。selectmodel,type,pricefromprinterwherecolor=’true’f)找出价格少于$2000并拥有12X或16XDVD的PC机的型号、速度和硬盘尺寸。把rd属性看作一个字符串属性。selectmodel,speed,hdfrompcwhereprice<2000andrd=’12xDVD’orrd=’16xDVD’习题6.1.4:基于习题5.2.4给出的数据库模式和资料写出后面的查询语句以及查询结果。Cla
4、sses(class,type,country,numGuns,bore,displacement)Ships(name,class,launched)Battles(name,date)Outcomes(ship,battle,result)a)找出至少装备10门火炮的船只所属类别名和制造国家selectcountry,typefromclasseswherenumGuns>=10b)找出在1918年以前下水的舰船的名字,并且把结果列名改为ShipName。selectnameasshipnamefromship
5、swherelaunched<1918c)找出所有在战役中被击沉的船只和那次战役的名字selectship,battlefromoutcomeswhereresult=’sunk’。d)找出具有相同类别名的所有船只。selectdistinctship1.class,ship1.typefromclassesasship1,classesasship2whereship1.type=ship2.typeandship1.class!=ship2.classorderbytypee)找出所有以”R.”字符开头的船只的
6、名字。selectnamefromshipswherenamelike’R%’!f)找出所有包括三个或三个以上单词的船只名字(例如KingGeorgeV)。selectshipfromoutcomeswhereshiplike‘%%%‘orshiplike‘%%%%’;习题6.2.2:根据习题5.2.1的数据库模式写出下列查询,并用那个习题给出的数据算出查询结果。Product(marker,model,type)PC(model,speed,ram,hd,rd,price)Laptop(model,speed,r
7、am,hd,screen,price)Printer(model,color,type,price)*a)查询硬盘容量至少在30G的手提电脑制造商及电脑的速度。selectmaker,speedfromproduct,laptopwherelaptop.model=product.modelandlaptop.hd>30*b)查询制造商B制造的任意类型的所有产品的型号和价格。selectmodel,pricefrompcwheremodelin(selectmodelfromproductwheremaker=’B
8、’)selectmodel,pricefromprinterwheremodelin(selectmodelfromproductwheremaker=’B’)selectmodel,pricefromlaptopwheremodelin(selectmodelfromproductwheremaker=’B’)a)查询只卖手提电脑不卖PC的厂商。selec