I am confused by the usage of alias
. For example, the query below works fine
select * from
(
select ROW_NUMBER() over (partition by prodid order by quantity desc) as 'rankin',prodid,quantity from sales
) A
where rankin=1
But when I modify it as shown in the snippet below I get the error: "Invalid column name 'rownumber'".
select ROW_NUMBER() over (order by quantity) as 'rownumber' from sales
where rownumber = 1
Please explain the difference.