在SELECT语句中重写相关的标量子查询

时间:2017-07-28 11:40:23

标签: sql presto

我在prestoDB中遇到相关标量子查询的问题。

SELECT 
    t.transaction_id, t.site_id, t.unit_id, t.quantity, t.reference_quantity,
    (SELECT 
            uf.factor
        FROM
            unit_factor uf
        WHERE
                uf.unit_id = t.unit_id
                AND uf.term_start <= t.term_start
                AND uf.impact_id IS NULL
                AND uf.site_id IS NULL
                AND uf.target_class_id IS NULL
                AND uf.position_id IS NULL
                AND uf.factor is not null
        ORDER BY uf.unit_id , uf.term_start DESC , uf.impact_id , uf.site_id , uf.target_class_id , uf.position_id
        LIMIT 1) as t
FROM
    transaction t;

有没有办法重写这个查询,以便PrestoDB可以执行它?

感谢。

0 个答案:

没有答案