日期:2014-05-18  浏览次数:20596 次

请问:这条SQL语句应该怎么解决,非常着急,谢谢DX了
D
DID   DMemo
D1   ...
D2   ...
D3   ...

C
CID   BInfo     C1   C2   C3   DID
C1   ...   1   2   3   D1
C2   ...   4   5   6   D2

V
VID   VNum   VInfo1   VInfo2   EID
V1   1   ...
V2   4   ...

E
EID   EName
E1   ...
E2   ...


SELECT     A.AMemo   AS   AMemmo,   C.CInfo1   AS   'CInfo1 ',   C.CInfo2   AS   'CInfo2 ',E.EName   AS   EName   FROM   A,B,C,D,E,V  
WHERE     B.AID   =   A.AID   AND   ((V.VNum   =   C.C1)   OR   (V.VNum   =   C.C2)   OR   (V.VNum   =   C.C3))   AND       E.EID   =   V.EID

如果C1或C2或C3这个条件在V表中存在,那么上面这条语句才可以查出数据。
问:
如果我需要查出的数据在V表中不存在,那应该怎么做!

谢谢

------解决方案--------------------
SELECT A.AMemo AS AMemmo, C.CInfo1 AS 'CInfo1 ', C.CInfo2 AS 'CInfo2 ',E.EName AS EName
FROM A inner join B on B.AID = A.AID
inner join C on ...
inner join D on ...
inner join E on ...
left join V on ((V.VNum = C.C1) OR (V.VNum = C.C2) OR (V.VNum = C.C3)) AND E.EID = V.EID

---格式这样写
但是楼主原来的语句好像是少很多条件阿?
------解决方案--------------------
((V.VNum != C.C1) OR (V.VNum != C.C2) OR (V.VNum != C.C3)) --????
------解决方案--------------------
按照楼主的意思这样改应该是可以的
------------------------------------
SELECT A.AMemo AS AMemmo, C.CInfo1 AS 'CInfo1 ', C.CInfo2 AS 'CInfo2 ',E.EName AS EName FROM A,B,C,D,E,V
WHERE B.AID = A.AID AND ((V.VNum = C.C1) OR (V.VNum = C.C2) OR (V.VNum = C.C3)) AND E.EID not in(select eid from V)
------解决方案--------------------
A,B表跟C,D,E,V表有什么关系吗?
------解决方案--------------------
SELECT A.AMemo AS AMemmo, C.CInfo1 AS 'CInfo1 ', C.CInfo2 AS 'CInfo2 ',E.EName AS EName FROM A,B,C,D,E,V
WHERE B.AID = A.AID AND

(V.VNum != C.C1) and (V.VNum != C.C2) and (V.VNum != C.C3)
AND E.EID = V.EID