gpt4 book ai didi

database - PostgreSQL 中的子查询优化

转载 作者:行者123 更新时间:2023-11-29 13:55:41 25 4
gpt4 key购买 nike

我有一张 table ,上面放了很多产品。我使用此查询来获取价格高于平均价格的所有产品:

select price, name from product
where price > (select avg(price) from compra)

由于我有很多产品,我需要优化查询。有帮助吗?

最佳答案

试试这个:

with query as (
select avg(price) as ave from product)

select price, name
from product p2, query
where p2.price > query.ave

关于database - PostgreSQL 中的子查询优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32430521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com