我有明天到期的数据,我必须使用12个表才能得到结果

时间:2015-05-21 00:02:01

标签: netezza

我在WHERE过滤器之前使用过JOIN ON,而我很难让它运行。它没有识别别名。我应该以通用的方式提供查询,还是这个问题没有必要?

编辑(加入查询)

SELECT DISTINCT T8.CONTRACTAGENTOFFICE,
   T1.CONTRACTID,
   T1.CONTRACTOTHERID,
   T1.CONTRACTDATEID1,
   T1.CONTRACTDATEID2,
   T1.CONTRACTDATEID3,
   T11.CONTRACTMARKET,
   T10.CONTRACTAGENTFIRSTNAME,
   T10.CONTRACTAGENTMIDDLENAME,
   T10.CONTRACTAGENTLASTNAME,
   T3.CONTRACTOWNERLASTNAME,
   T3.CONTRACTOWNERFIRSTNAME,
   T3.CONTRACTOWNERMIDDLENAME,
   T3.CONTRACTOWNERBIRTHDATE,
   T3.CONTRACTOWNERUNIQUEID,
   T3.CONTRACTROLETYPE,
   T9.WIDGETNAME,
   T15.CONTRACTTRANSACTIONGROUPING,
   T6.CONTRACTOFFERINGNAME,
   SUM (T12.CONTRACTTRANSACTIONDOLLARS),
   MIN (T12.CONTRACTTRANSACTIONDATE)
FROM TABLE1 T1,
   TABLE2 T2,
   TABLE3 T3,
   TABLE4 T4,
   TABLE5 T5,
   TABLE6 T6,
   TABLE7 T7,
   TABLE8 T8,
   TABLE9 T9,
   TABLE10 T10,
   TABLE11 T11,
   TABLE12 T12,
   TABLE13 T13,
   TABLE14 T14,
   TABLE15 T15,
   TABLE16 T16
   JOIN TABLE1
   ON T1.CONTRACTID = T3.CONTRACTID
   JOIN TABLE3
   ON T3.CONTRACTPERSONTYPE = T5.CONTRACTPERSONTYPE
   JOIN TABLE4
   ON T1.CONTRACTID = T4.CONTRACTID
   JOIN TABLE 12
   ON T1.CONTRACTID = T12.CONTRACTID
   JOIN TABLE2
   ON T1.CONTRACTID = T2.CONTRACTID
   JOIN TABLE10
   ON T2.CONTRACTAGENTID = T10.CONTRACTAGENTID
   JOIN TABLE9 PRODUCTS
   ON T4WIDGETID = T9.WIDGETID
   JOIN TABLE 12
   ON T9.WIDGETID = T12.WIDGETID
   JOIN TABLE7
   ON T7.CONTRACTAGENTOFFICE = T8.CONTRACTAGENTOFFICE
   JOIN TABLE 16 TI_GROUP_RLSHPS
   ON T16.CONTRACTTRANSACTIONTYPE = T12.CONTRACTTRANSACTIONTYPE
   JOIN TABLE 12
   ON T12.CONTRACTTRANSACTIONTYPE = T13.CONTRACTTRANSACTIONTYPE
   JOIN TABLE14
   ON T14.TRANSACTIONID = T13.TRANSACTIONID
   JOIN TABLE15
   ON T15.CONTRACTTRANSACTIONGROUPING = T16.CONTRACTTRANSACTIONGROUPING
   LEFT JOIN TABLE6
   ON T1.CONTRACTID = T6.CONTRACTID
   AND T1.CONTRACTOTHERID IN ('1',
                              '21',
                              '47')
   AND T1.CONTRACTDATEID1 BETWEEN TO_DATE ('2012/07/01', 'yyyy/mm/dd') AND TO_DATE ('2014/09/30', 'yyyy/mm/dd')
   AND T1.CONTRACTDATEID2 BETWEEN TO_DATE ('2012/07/01', 'yyyy/mm/dd') AND TO_DATE ('2014/09/30', 'yyyy/mm/dd')
   AND T1.CONTRACTDATEID3 BETWEEN TO_DATE ('2012/07/01', 'yyyy/mm/dd') AND TO_DATE ('2014/09/30', 'yyyy/mm/dd')
   AND T3.CONTRACTTYPE                 IN (1,2,5)
   AND T11.CONTRACTMARKET              IN (1,2,3,4,5,6,7)
   AND T9.WIDGEGROUP                   IN (1,11)
   AND T15.CONTRACTTRANSACTIONGROUPING IN (1,4)
   AND T6.CONTRACTOFFERINGTYPE         IN (0,1,3)
   AND T3.CONTRACTROLETYPE             IN (1,7)
   AND T8.CONTRACTAGENTOFFICENAME LIKE 'XXXX%'
   AND T8.CONTRACTAGENTORIGINATINGOFFICE IN (1,13,21,47)
   AND T14.TRANSACTIONORIGINATINGID      IN (A,
                                             B,
                                             C,
                                             D,
                                             E)
GROUP BY T8.CONTRACTAGENTOFFICE,
   T1.CONTRACTID,
   T1.CONTRACTOTHERID,
   T1.CONTRACTDATEID1,
   T1.CONTRACTDATEID2,
   T1.CONTRACTDATEID3,
   T11.CONTRACTMARKET,
   T10.CONTRACTAGENTFIRSTNAME,
   T10.CONTRACTAGENTMIDDLENAME,
   T10.CONTRACTAGENTLASTNAME,
   T3.CONTRACTOWNERLASTNAME,
   T3.CONTRACTOWNERFIRSTNAME,
   T3.CONTRACTOWNERMIDDLENAME,
   T3.CONTRACTOWNERBIRTHDATE,
   T3.CONTRACTOWNERUNIQUEID,
   T3.CONTRACTROLETYPE,
   T9.WIDGETNAME,
   T15.CONTRACTTRANSACTIONGROUPING,
   T6.CONTRACTOFFERINGNAME

1 个答案:

答案 0 :(得分:0)

您的问题是您在from子句中列出了每个表两次。您可以使用FROM TABLEA,TABLEB ... WHERE表单或FROM TABLEA JOIN TABLEB ON ... WHERE表单,但不要混用它们。

你的FROM子句应该是这样的:

FROM TABLE1 T1 
   JOIN TABLE2
   ON T1.CONTRACTID = T2.CONTRACTID
   JOIN TABLE3
   ON T1.CONTRACTID = T3.CONTRACTID
   JOIN TABLE4
   ON T1.CONTRACTID = T4.CONTRACTID
...
WHERE 
....