有三张表:销售商(xss) ,产品(cp),销售产品(xscp),销售商(xss)与产品(cp)是n对m的关系,它们通过之间的联系是表:销售产品(xscp).现在要查询“销售了销售编号(xsbh)为000001的销售商,所销售的全部产品的销售商名称”. 现在有两种写法:
1.我自己写的语句是
use cpxs
select xsmc
from xss where xsbh in(
select xsbh
from xscp
where cpbh in(select cpbh
from cp
where cpmc in (select cpmc from cp,xscp,xss where cp.cpbh=xscp.cpbh and xscp.xsbh = xss.xsbh and xss.xsbh='000001' )))这样写查询出来的是销售了000001号销售商的销售的产品的销售商名称,并不符合条件销售了销售编号(xsbh)为000001的销售商,所销售的“全部产品”的销售商名称.
针对上述问题,正确答案是
2.select xsmc from xss
where xsbh in
( select xsbh from xscp xscp1
where not exists
(select * from xscp as xscp2
where xscp2.xsbh='000001'and not exists
(select * from xscp xscp3 where xscp3.xsbh=xscp1.xsbh and
xscp3.cpbh=xscp2.cpbh)
)
)
请问连续使用2个NOT EXISTS 时表示双重否定吗 ?谁能将2的求解思路具体给我解释下 啊 ,我自己想了3天了 ,每天都只做了这一个题目,效率实在太低了,盼望高手指点迷津!
1.我自己写的语句是
use cpxs
select xsmc
from xss where xsbh in(
select xsbh
from xscp
where cpbh in(select cpbh
from cp
where cpmc in (select cpmc from cp,xscp,xss where cp.cpbh=xscp.cpbh and xscp.xsbh = xss.xsbh and xss.xsbh='000001' )))这样写查询出来的是销售了000001号销售商的销售的产品的销售商名称,并不符合条件销售了销售编号(xsbh)为000001的销售商,所销售的“全部产品”的销售商名称.
针对上述问题,正确答案是
2.select xsmc from xss
where xsbh in
( select xsbh from xscp xscp1
where not exists
(select * from xscp as xscp2
where xscp2.xsbh='000001'and not exists
(select * from xscp xscp3 where xscp3.xsbh=xscp1.xsbh and
xscp3.cpbh=xscp2.cpbh)
)
)
请问连续使用2个NOT EXISTS 时表示双重否定吗 ?谁能将2的求解思路具体给我解释下 啊 ,我自己想了3天了 ,每天都只做了这一个题目,效率实在太低了,盼望高手指点迷津!
假如
A销售了1,2
B销售了1
C销售了2
D销售了1,2
那么所所得结果中D是符合条件的结果,因为只有D销售了A所销售的“全部产品”。注意
条件“全部产品”
A销售了1,2
B销售了1
C销售了2
D销售了1,2
那么所所得结果中D是符合条件的结果,因为只有D销售了所
销售的“全部产品”。注意 条件“全部产品”
xscp1 和 xscp2 xscp3 它们都是xscp这张表的别名啊 ! 三张表分别是:
销售商(销售编号,销售名称) 即xss(xsbh,xsmc)
产品 (产品编号,产品名称) 即cp(cpbh,cpmc)
销售产品(销售编号,产品摆好) 即xscp(xsbh,cpbh)