I have a table app_order with fields price (a number) and side (side can be either ‘up’ or ‘down’).
I need to write a postgreSQL condition within a WHERE clause that filters app_order entries where price is both:
-
bigger than the average of 2 prices (max price with side=’up’ and min price with side=’down’) – 1 AND
-
smaller than the average of 2 prices (max price with side=’up’ and min price with side=’down’) + 1
How can I concatenate where conditions to do this?
At the end, I need a query similar to this:
SELECT
market AS "MARKET",
SUM(size*price) AS "SUM"
FROM
app_order
WHERE
--Missing condition here AND
GROUP BY
market
ORDER BY
market ASC
Thanks a lot!