我有一个查询返回avg(price)
select avg(price)
from(
select *, cume_dist() OVER (ORDER BY price desc) from web_price_scan
where listing_Type='AARM'
and u_kbalikepartnumbers_id = 1000307
and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
and price>( select avg(price)* 0.50
from(select *, cume_dist() OVER (ORDER BY price desc)
from web_price_scan
where listing_Type='AARM'
and u_kbalikepartnumbers_id = 1000307
and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
)g
where cume_dist < 0.50
)
and price<( select avg(price)*2
from( select *, cume_dist() OVER (ORDER BY price desc)
from web_price_scan
where listing_Type='AARM'
and u_kbalikepartnumbers_id = 1000307
and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
)d
where cume_dist < 0.50)
)s
having count(*) > 5
如果没有可用值,如何使它返回0?
1
您确定查询的格式正确吗?
—
吕克M
@LucM:不能是格式正确的查询。(“具有”子句而没有“分组依据”子句。)
—
Mike Sherrill'Cat Recall'
一切工作正常,除了有时不遵守规则不会返回任何内容。另外,我平均如何购物,我认为这有什么可能吗?多个选择
—
安德鲁
from web_price_scan
是单独的选择;不知道这里出了什么问题?
可以使用不带
—
bruceskyaus
having
子句的子句group by
(默认为单个组)。它充当where
汇总结果的子句。在这种情况下,仅当第一级子查询返回的行超过5行时,才返回行。