8行SQL语句中请大侠翻译!
来源:百度知道 编辑:UC知道 时间:2024/06/28 21:36:37
有三张表:销售商(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天了 ,每天都只做了这一个题目,效率实在太低了,盼望高手指点迷津!
题目的意思是
假如
A销售了1,2
B销售了1
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
是不是xscp里面有xsmc xsbh cpbh.?
经销商经销的的商品决定于表 xscp?
当以上答案为真,那么我有一点看法:
SELECT xsmc from xscp where cpbh
IN(
select cpbh from xscp where xsmc =
(
select xsmc form xscp where xsbh ='000001'
)
);
思路就是这样,如果有问题请楼主补充,我再作更改~
我也想对这个题目了解多一点,标准答案里面xscp1 xscp2 xscp3那里暂时还理解不到必要性,同望高手作答
***************************
是不是如果000001号单的是经销商A经销产品,查到A共经销了产品
1 2 3 4 5号产品,那么符合题目要求的经销商就是经销了 1 2 3 4 5号产品或者1 2 3 4 5 6 .........(更多) 的经销商??
注意他们的执行优先级