Netezza中的相关查询

时间:2013-09-08 19:43:12

标签: netezza correlated-subquery

当我在oracle数据库中进行如下查询时,如何在Netezza数据库中重写相关查询...

select table1.column1,
case when table2.column2='xxxx' then
             ( select max(table3.column3) 
                  from table3  
                  where table3.column4=4 
                    and table3.column2=table1.column2 and
                        table3.column3=table4.column4
              ) 
else null
end
from table1,table2, table4.

1 个答案:

答案 0 :(得分:1)

考虑改变结构。

SELECT table1.column1,
CASE WHEN table2.column2='xxxx' THEN
sub_tbl3.mx
ELSE NULL
END
FROM table1 inner join
     table2
     ON table1.column1=table2.column1 inner join
    table4
    ON table1.column2=table4.column4 left outer join
(SELECT table3.column2,
     table3.column3,
      MAX(table3.column3) AS mx
FROM table3
WHERE table3.column4=4
GROUP BY  table3.column2,
     table3.column3) sub_tbl3
ON table3.column2=table1.column2
AND table3.column3=table4.column4