SQL语句上机题Word格式.docx
《SQL语句上机题Word格式.docx》由会员分享,可在线阅读,更多相关《SQL语句上机题Word格式.docx(7页珍藏版)》请在冰豆网上搜索。
c)找出所有打印机制造厂商。
selectdistinctmaker
fromproduct
wheretype='
printer'
d)找出价格在$2000以上的手提电脑的型号、内存大小和屏幕尺寸。
selectmodel,ram,screen
fromlaptop
whereprice>
2000
*e)找出关系Printer中所有彩色打印机元组,注意属性color是一个布尔类型。
selectmodel,type,price
fromprinter
wherecolor='
true'
f)找出价格少于$2000并拥有12X或16XDVD的PC机的型号、速度和硬盘尺寸。
把rd属性看作一个字符串属性。
selectmodel,speed,hd
2000andrd='
12xDVD'
orrd='
16xDVD'
习题6.1.4:
基于习题5.2.4给出的数据库模式和资料写出后面的查询语句以及查询结果。
Classes(class,type,country,numGuns,bore,displacement)
Ships(name,class,launched)
Battles(name,date)
Outcomes(ship,battle,result)
a)找出至少装备10门火炮的船只所属类别名和制造国家
selectcountry,type
fromclasses
wherenumGuns>
=10
b)找出在1918年以前下水的舰船的名字,并且把结果列名改为ShipNama
selectnameasshipname
fromships
wherelaunched<
1918
c)找出所有在战役中被击沉的船只和那次战役的名字
selectship,battle
fromoutcomes
whereresult='
sunk'
。
d)找出具有相同类别名的所有船只。
selectdistinctship1.class,ship1.type
fromclassesasship1,classesasship2
whereship1.type=ship2.typeandship1.class!
=ship2.class
orderbytype
e)找出所有以”R字符开头的船只的名字。
selectname
wherenamelike'
R%'
!
f)找出所有包括三个或三个以上单词的船只名字(例如KingGeorgeV)
selectship
whereshiplike‘%%%‘orshiplike‘%%%%'
;
习题6.2.2:
根据习题5.2.1的数据库模式写出下列查询,并用那个习题给出的数据算出查询结果。
*a)查询硬盘容量至少在30G的手提电脑制造商及电脑的速度。
selectmaker,speed
fromproduct,laptop
wherelaptop.model=product.modelandlaptop.hd>
30
*b)查询制造商B制造的任意类型的所有产品的型号和价格。
selectmodel,price
)selectmod
wheremodelin(selectmodelfromproductwheremaker='
B'
wheremodelin(selectmodelfromproductwheremaker二b)查询只卖手提
电脑不卖PC的厂商。
wheremakernotin(selectmakerfromproductwheretype='
pc'
)andtype='
laptop'
c)
d)查询出现在两种或两种以上PC中的硬盘的尺寸。
e)查询每对具有相同速度和RAM的PC机,每一对只出现一次。
例如,如果(i,j)符合,则(j,i)就不能出现在结果中出现。
f)查询生产至少两种速度大于等于1000的计算机(PC或手提)的厂商。
习题6.2.3根据习题5.2.4的数据库模式写出下面的查询,并用那个习题给出的数据算出查询结果。
Clasaes(class,type,country,numGuns,bore,displacement)Ships(name,class,launched)
Battles(name,date)
Outcomes(ship,battle,result)
a)找出重量超过35000吨的船只。
fromships,classes
whereships.class二classes.classanddisplacement>
35OO0b找出参加过Guadalcanal战役的船只的名字、排水量和火炮数量。
selectname,displacement,numGuns
fromclasses,ships,outcomes
whereships.class=classes.classandships.name=outcomes.shipandbattle='
Guadalcanal'
c)列出所有数据库中提到的船只(注意,并非所有的船只都出现在ships
关系中)。
selectdistinctships.name
fromships;
selectdistinctship
whereshipnotin(
fromships)
d)找出同时具有战列舰和巡洋舰的国家。
e)找出曾在某次战役中受创但后来又在其他战役中出现的船只。
町找出参战船只至少有三艘来自同一个国家的战役。
习题6.3.1:
基于习题5.2.1的数据库模式写出后面的查询
每题的答案中,你应当至少使用一个子查询,并且用两种不同的方法写出每个查询(例如,使用各种不同的操作符EXISTSIN、ALL和ANY)
*a)找出速度在1200以上的PC的制造商。
b)找出价格最高的打印机。
c)找出速度比任何一台PC都慢的手提电脑。
d)找出具有最高价格的产品(PC手提电脑或打印机)的型号。
e)找出最低价格的彩色打印机的制造商。
f)在所有的PC中,找出具有最快速度并具有最少RAM的PC制造商。
习题6.3.2基于习题5.2.4的数据库模式写出后面的查询
Classes(class,type,country,numGuns,bore,displacement)Ships(name,class,launched)
Battles(name,date)
Outcomes(ship,battle,result)
每题的答案中,你应当至少使用一个子查询,并且使用两种不同的方法写
出每个查询(例如,使用各种不同的操作符EXISTSIN、ALL和ANY。
a)找出拥有火炮数量最多的船只所属的国家。
*!
b)找出至少有一艘船在战役中被击沉的船只种类。
c)找出具有16英寸口径火炮的船只的名字。
d)找出Kongo类型船只参加的战役。
e)找出具有相同口径火炮的船只中火炮数量最多的船只名字。
习题6.4.6:
根据习题5.2.1的数据库模式写出后面的查询,再用该习题给出
的数据算出该查询结果。
*(a)查询PC速度的平均值。
(b)查询价格在$2000以上的手提电脑的平均
值。
(c)查询制造商A生产的PC的平均价格。
(d)查询制造商D生产的PC和手提电脑的平均价格。
(e)求不同速度的PC平均价格。
(f)找出各个制造商生产的手提电脑的平均价格。
(g)找出至少生产三种不同型号PC机的制造商。
(h)找出各个制造商制造的PC的最高价格。
(i)找出速度在800以上的PC的平均价格。
(j)对于所有生产打印机的制造商,查询其生产的PC机的硬盘平均大小。
习题6.4.7基于习题5.2.4给出的数据库模式和数据写出后面的查询语句以
及查询结果。
Classes(class,type,country,numCuns,bore,displacement)Shipsiame,class,launched)
Battles(name,date)
a)找出战舰类型的数量。
b)找出不同类型战舰拥有的平均火炮数量。
c)找出战舰的平均火炮数量。
注意c)和b)的不同在于:
在计算均值的时候,是使用战舰的数目还是战舰的类型数目。
d)找出每一类型(class)的第一艘船下水的年份。
e)找出每一类型中被击沉船的数目。
f)找出至少有3艘