I always struggle with sql subqueries. For example the answer to this question:
select userid,
my_date,
...
from
(
select userid,
my_Date,
...
max(my_date) over (partition by userid) max_my_date
from users
)
my_date = max_my_date
Why can't it just be:
select userid,
my_Date,
...
max(my_date) over (partition by userid) max_my_date
from users
where
my_date = max_my_date
I know it is not correct, but after all, the first select only selects something from the result of the second select, plus my_date = max_my_date
. In what kind of situation should I think about using this kind of subquery (besides the normal in, exist, etc)?