多表多条件多主键关联查询
表A
FBID,LUBH,Date,JDRQ...
表B
FBID,LUBH,Date,AZRQ,AZBZ
表C
FBID,LUBH,Date,SHRQ,SHBZ
表D
FBID,LUBH,Date,DSRQ
所有的表都是以 FBID,LUBH,Date为主键
现在需要按表A的JDRQ和表C的SHRQ,表的DSRQ为条件查询出一张包含了ABCD四表数据的表,如何写啊,都晕死了。
------解决方案--------------------你的条件是什么呀?输出又是什么呀?
------解决方案--------------------Select A.*, B.AZRQ, B.AZBZ, C.SHRQ, C.SHBZ, D.DSRQ
From A
Inner Join B On A.FBID = B.FBID And A.LUBH = B.LUBH And A.[Date] =B.[Date]
Inner Join C On A.FBID = C.FBID And A.LUBH = C.LUBH And A.[Date] =C.[Date]
Inner Join D On A.FBID = D.FBID And A.LUBH = D.LUBH And A.[Date] =D.[Date]
Where A.JDRQ = 條件 And C.SHRQ = 條件 And D.DSRQ = 條件
------解决方案--------------------Or
Select A.*, B.AZRQ, B.AZBZ, C.SHRQ, C.SHBZ, D.DSRQ
From A, B, C, D
Where A.FBID = B.FBID And A.LUBH = B.LUBH And A.[Date] =B.[Date]
And A.FBID = C.FBID And A.LUBH = C.LUBH And A.[Date] =C.[Date]
And A.FBID = D.FBID And A.LUBH = D.LUBH And A.[Date] =D.[Date]
And A.JDRQ = 條件 And C.SHRQ = 條件 And D.DSRQ = 條件
------解决方案--------------------试试union,如:
select A.FBID,A.LUBH,A.Date,A.JDRQ AB,1 CD from A union
select B.FBID, B.LUBH,B.Date,B.AZRQ AB,B.AZBZ CD from B
where A.JDRQ= ' ' and/or B.AZRQ= ' '
不过这样会有很多数据的。。。