¿Cómo puedo usar COALESCE (precio)? Debido a que recibí el error "no agregado", ¿cómo puedo usar todas las columnas en seleccionar con agrupar por? COALESCE (precio): significa el primer valor en el grupo, pero también necesito el primer y el último valor en el grupo, pero ¿cómo puedo hacerlo?
select MAX(price) as high, MIN(price) as low, COALESCE(price) as open, date_trunc('second', created_at) as secondVal from "eur_usd_ticks" where "created_at" > '2020-07-19 23:15:49' and "created_at" <= '2020-07-19 23:49:09' group by secondVal order by "created_at" descEstructura: precio|creado_en
coalesce no sirve de nada. prueba esto:
SELECT MAX(price) as high, MIN(price) as low, (ARRAY_AGG(price ORDER BY created_at ASC))[1] AS open_price, (ARRAY_AGG(price ORDER BY created_at DESC))[1] as close_price, date_trunc('second', created_at) as secondVal from "eur_usd_ticks" where "created_at" > '2020-07-19 23:15:49' and "created_at" <= '2020-07-19 23:49:09' group by secondVal order by secondVal desc