在左边你会看到我为一个表设计的,在右边你会看到下面 SQL 中子查询的结果。我正在尝试patientID,claimsFromDate,claimsThroughDate
在 tblClaims 的三个字段上加入子查询,并让外部查询将正确tblClaims.ID
的与三部分连接相关联。
我得到的错误:
第 3 行,关键字附近的
and
语法不正确 选择 ) 附近的语法不正确,第 12 行
select tblClaims.id, t.primaryCode
from t
(
select patientid, claimsfromdate, claimsthroughDate, primarycode from myTable
union
select patientid, claimsfromDate, claimsthroughDate, secondaryCode from myTable
union
select patientID, claimsfromdate, claimsthroughDate, tertiarycode from myTable
) as t
inner join t on tblclaims.patientid=t.patientid
and tblclaims.claimsfromdate=t.claimsfromdate
and tblclaims.cllaimsthroughdate=t.claimsfromdate
编辑:内部查询是协调多列字段。它返回 150 万行。我运行的固定查询返回 350 万,即
select tblClaims.id, t.primarycode
from
(
select patientid, claimsfromdate, claimsthroughDate, primarycode from myTable
) as t
inner join tblclaims on tblclaims.patientid=t.patientid
and tblclaims.claimsfromdate=t.claimsfromdate
and tblclaims.cllaimsthroughdate=t.claimsfromdate