0

我有 3 个表:AuditCheckCriteria 作为 T1,Learners 作为 T2 和 LearnerAuditRegistrations 作为 T3,结构如下:

  T1: CheckID     CheckName                      
          1       'Stage One'
          2       'Stage Two'
          3       'Stage Three'

  T2   LearnerID   LearnerName
          10         'John'
          11         'Peter'
          12         'Paul'

  T3: LearnerAuditID  LearnerID  CheckID
          1             10         1
          2             10         2
          3             11         1
          4             11         2
          5             11         3

我想要以下输出:

T2.LearnerID, T1.CheckID, T3.CheckID
      10           1           1
      10           2           2
      10           3          NULL
      11           1           1
      11           2           2
      11           3           3
      12           1          NULL
      12           2          NULL
      12           3          NULL

(T2 和 T3 各包含超过 20000 行)

任何帮助表示赞赏!

4

2 回答 2

1

看起来您想要 T1 和 T2 中的所有值组合,并从 T3 中查找。如果是这样,则执行以下操作:

with t1vals as (select distinct checkID from t1),
     t2vals as (select distinct LearnerId from t2)
select t2vals.LearnerId, t1vals.CheckId, t3.CheckId
from t1vals cross join
     t2vals left outer join
     t3
     on t3.LearnerId = t2vals.LearnerId and
        t3.CheckId = t1vals.CheckId
于 2012-07-24T14:20:06.340 回答
0

使用(T2 交叉连接 T1)左连接 T3..

于 2012-07-24T14:18:49.803 回答