Why can't I use Alias even after nesting the code, it seems to not work, I used a different approach which works but doesn't look good.
This doesn't work
SELECT Year,
Number_of_rides
FROM (SELECT DATEPART(YEAR, [starttime]) AS Year,
COUNT (*) AS Number_of_rides
FROM [dbo].[Citi-Bike-Trip-Data]) AS x
GROUP BY x.Year,
x.Number_of_rides
ORDER BY Year ASC
This works
SELECT
DATEPART(YEAR,
[starttime]) AS Year,
COUNT (*) AS Number_of_rides
FROM
[dbo].[Citi-Bike-Trip-Data]
GROUP BY DATEPART(YEAR, [starttime])