主查询结果在子查询中再次使用

时间:2018-07-17 03:45:22

标签: sql

我对此Sql有一个改进的问题:

select
    A.id,
    ...
from
    pub_log A
where
    1 = 1
    and A.scope >= 2
    and A.exeby >= 2
    and A.executioner not in (
        select
            B.executioner
        from
            pub_log B
        where
            A.executioner in (
                'somename'
            )
            and (
                A.scope = 0
                or A.scope = 2
            )
    )
order by
    A.create_date desc limit 20 offset 0 

我在PostgreSQL中使用此查询 我在同一张桌子上一次选择查询两次 在行动中,这是浪费 那我该如何改善这个sql呢?

1 个答案:

答案 0 :(得分:0)

嘿,

您不能真正通过这种方式真正改善查询2次查询同一张表。 您需要子查询,因为您没有有关execution子手的信息。

希望您的问题正确无误:-) 抱歉伦敦糟糕

相关问题