有三张表:销售商(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)
)
)
请问1.连续使用2个NOT EXISTS 时表示双重否定吗 ?
2.谁能将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)
)
)
请问1.连续使用2个NOT EXISTS 时表示双重否定吗 ?
2.谁能将2的求解思路具体给我解释下 啊?
3.高手能将您的方法或是求解思路下下来吗 ?
谢谢您 祝您好人一生平安!!!
解决方案 »
- 让哥蛋疼的cast函数
- fcuandy接分贴之一
- ~~邹建大哥在吗?求助-关于sql server 死锁跟踪标记对sql server性能影响
- 没分了,但请请教:表设计的一个小问题,有经验的指点一下,比较头疼!!!
- SQL SERVER 2005安装过程中的问题
- 这个SQL怎么写?
- [SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: '@P1' 附近有语法错误
- Sql Server2005导出数据到sql server2000
- 请问VFP问题
- 如何把SYSBASE库中的数据倒入到SQL SERVER数据库中
- SQL经典问题求解! 高手进!
- SQL疑难问题
-------------
A 销售 1,2
B 销售 1,3
那么销售了1的的销售商是A和B,那这个全部产品是指什么?
假如
A销售了1,2
B销售了1
C销售了2
D销售了1,2
那么所所得结果中D是符合条件的结果,因为只有D销售了所销售的“全部产品”。注意
条件“全部产品”
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)