I am struggling to simplify / alias the following SQL query. I am fairly new to SQL, hopefully someone can point me to the right direction.
As the 2nd part of the line is pretty much identical to the 1st part other than the Where condition, I am hoping to just call it a variable "X".
I tried experimenting with different parentheses and order but I kept getting syntax error. My code is as follows:
select
(select avg(stars) from LONG EXPRESSION where Condition < Y)
-
(select avg(stars) from LONG EXPRESSION where Condition > Y)
Ideally I would like to achieve something similar to
select
(select avg(stars) from (LONG EXPRESSION) X where Condition < Y)
-
(select avg(stars) from X where Condition > Y)
Thanks for your help.
Dan