Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 内部联接中的SQL查询问题_Sql Server 2005 - Fatal编程技术网

Sql server 2005 内部联接中的SQL查询问题

Sql server 2005 内部联接中的SQL查询问题,sql-server-2005,Sql Server 2005,我有表Creditcard,Childcreditcard1,Childcreditcard2 儿童信用卡1 CreditcardID TranscationDatetime 22222132132 2010-04-11 12:36:10.210 22222132134 2011-04-11 12:36:10.210 12364132122 2019-04-11 12:36:10.210 45677132124 2011-04-11 12:36:10.210 456771321

我有表
Creditcard
Childcreditcard1
Childcreditcard2

儿童信用卡1

CreditcardID  TranscationDatetime
22222132132   2010-04-11 12:36:10.210
22222132134   2011-04-11 12:36:10.210
12364132122   2019-04-11 12:36:10.210
45677132124   2011-04-11 12:36:10.210
45677132124   2012-04-11 12:36:10.210
儿童信用卡2

CreditcardID  TranscationDatetime
22222132132   2010-04-11 12:36:10.210
22222732134   2011-04-11 12:36:10.210
12364132192   2019-04-11 12:36:10.210
万事达信用卡

CreditcardID            primaryCreditID
22222132132     22222132132             
22222132134     22222132132             
12364132122     12364132122         
45677132124     45677132124
45677232124     45677232124     
78567723212     78567723212 
23677232124     23677232124 
45678944343     45678944343
22222732134     22222732134
12364132192              12364132192
现在,从这三个表中,我需要得到
creditcard
,它不仅与
MasterCreditcard
中的
creditcard
中的
Childcreditcard1
匹配,
Childcreditcard2
表将始终位于
MasterCreditcard
表中

结果应该是这样的表

 45677232124
 78567723212
 23677232124
 45678944343
我的问题是:

select 
      distinct(cc.CreditcardID) 
from 
      MasterCreditcard  CC  
inner JOIN 
      Childcreditcard1 c1 ON CC.CreditcardID <> c1.CreditcardID 
inner JOIN 
      Childcreditcard2 c2 ON CC.CreditcardID <> c2.CreditcardID  
选择
独特(抄送信用卡)
从…起
万事达信用卡
内连接
CC.CreditcardID c1.CreditcardID上的Childcreditcard1 c1
内连接
CC.CreditCardC2.CreditCardC2.CreditcardID上的Childcreditcard2 c2

我试过这样做,但这给出了
MasterCreditcard
表中所有
creditcard
的结果,这是错误的

试试看,这可能对您有用

select distinct(cc.CreditcardID) from MasterCreditcard  CC  
left JOIN Childcreditcard1 c1 ON CC.CreditcardID =c1.CreditcardID  
left JOIN Childcreditcard2 c2 ON CC.CreditcardID =c2.CreditcardID   
where c1.CreditcardID  is null or c2.CreditcardID   is null
我的答案是基于这张图片,第二张图片是左外角的盒子


答案对您有帮助吗?@happysmile-可以说这是什么吗?从MasterCreditcard中选择distinct(cc.CreditcardID)cc left outer JOIN Childcreditcard1 c1 ON cc.CreditcardID=c1.CreditcardID left outer JOIN Childcreditcard2 c2 ON cc.CreditcardID=c2.CreditcardID其中c1.CreditcardID为空,c2.CreditcardID为空