Ho una query che restituisce AVG (prezzo)PostgreSQL restituisce 0 se il valore restituito è nullo
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
come farlo tornare 0 se nessun valore è disponibile?
Sei sicuro che la query è ben formata? –
@LucM: non può essere una query ben formata. (clausola "having" senza clausola "group by".) –
tutto funziona correttamente, tranne che a volte, quando le regole non vengono soddisfatte, non restituisce nulla. Inoltre, come posso gorupare in media, non penso sia possibile || qual è il punto? Multiple select 'from web_price_scan' sono selezioni separate; non sei sicuro di quale sia il problema qui? – Andrew