从多个表中选择多个列

时间:2013-01-17 11:30:41

标签: sql netezza

我为netezza db构建了流动的SQL:

select t.TRADE_OID, t.TRADE_ID, t.TRADE_VERSION, t.TRADE_SOURCE_SYSTEM, tl.LINK_PARENT_ID, 
tl.LINK_PARENT_VERSION, tc.CHARGE_AMOUNT FROM EQ_MO_TRADE (NOLOCK) t, EQ_MO_TRADE_CHARGE (NOLOCK) tc, EQ_MO_TRADE_LINKAGE (NOLOCK) tl 
WHERE t.Last_update_time >= '2013-01-09 00:00:00' 
AND t.last_update_time < '2013-01-10 00:00:00' 
AND t.TRADE_OID = tl.TRADE_OID
AND t.TRADE_OID = tc.TRADE_OID
AND tc.CHARGE_NAME = 'Commission'

但是我得到了一般错误:

 [SELECT - 0 row(s), 0.000 secs]  [Error Code: 1100, SQL State: HY000]  ERROR:  'select 

t.TRADE_OID, t.TRADE_ID, t.TRADE_VERSION, t.TRADE_SOURCE_SYSTEM, tl.LINK_PARENT_ID, tl.LINK_PARENT_VERSION, tc.CHARGE_AMOUNT FROM EQ_MO_TRADE (NOLOCK) t, EQ_MO_TRADE_CHARGE (NOLOCK) tc, EQ_MO_TRADE_LINKAGE (NOLOCK) tl 
WHERE t.Last_update_time >= '2013-01-09 00:00:00' 
AND t.last_update_time < '2013-01-10 00:00:00' 
AND t.TRADE_OID = tl.TRADE_OID
AND t.TRADE_OID = tc.TRADE_OID
AND tc.CHARGE_NAME = 'Commission' limit 1000'
error                                                                                                                                                         

^ found "(" (at char 150) expecting `EXCEPT' or `FOR' or `INTERSECT' or `ORDER

角色150介于这两者之间:

交易和(NOLOCK)

我的语法似乎正确,但DBVisualiser不会运行查询。

1 个答案:

答案 0 :(得分:1)

Netezza Database User's Guide (5.0.x)所述,Netezza不支持WITH (NOLOCK)等优化提示。

来自第3.36页

  
    

请注意,无需用户干预,命令或提示

  

无论如何,NOLOCK被广泛视为dubious practice

但是,Netezza支持INNER JOIN语法(p2.17)

我会按如下方式重写查询:

SELECT
    t.TRADE_OID, 
    t.TRADE_ID, 
    t.TRADE_VERSION, 
    t.TRADE_SOURCE_SYSTEM, 
    tl.LINK_PARENT_ID, 
    tl.LINK_PARENT_VERSION, 
    tc.CHARGE_AMOUNT 
FROM 
  EQ_MO_TRADE t 
    INNER JOIN EQ_MO_TRADE_CHARGE tc
            ON (t.TRADE_OID = tc.TRADE_OID)
    INNER JOIN EQ_MO_TRADE_LINKAGE tl 
        ON (t.TRADE_OID = tl.TRADE_OID)
WHERE 
  t.Last_update_time >= '2013-01-09 00:00:00' 
  AND t.last_update_time < '2013-01-10 00:00:00' 
  AND tc.CHARGE_NAME = 'Commission'