【问题3】
如下的SQL语句是书店用于查询“所有订购了bid为‘123-456’图书的用户订购其他图书的情况”的不完整语句,请在空缺处填入正确的内容。
Select bid
From Orderlist A
Where not exists(Select*from Orders B
where A.ordemum=B.ordemum and B.cid (3)
(Select cid from Ordcrlist C,Orders D
where (4) .bid=’123-456’
and (5) =D.ordemum))
参考答案:not in
(2)C
(3)C.ordemum
解析:
[分析]:
问题3:根据题意分析,最内层的SQL语句查找订购了123-456的客户cid,ordemum只出现在Orderlist和order中,所以 (5) 中应填写C.ordemum,(4) 中应该填写C,而要求寻找这些用户还订购哪些其他书籍,所以(3)中应填写in。
填写后完整的SQL语句如下:
Select bid
From Orderlist A
Where not exists(Select*fromOrdersB
where A.ordernum=B.ordernym and B.cid in
(Select cid from Orderlist C,Orders D
where C .bid=’123-456’
and C.ordemum =D.ordemum))