I have a sql query below, but I am facing a problem while executing it.
SELECT * from (Select row_number() OVER(Order By FloorUserId) as 'row_number', FloorUserId, max(CASE WHEN AreaId='[G]' or AreaId=N'L01' THEN 'X' ELSE ' ' END) as 'L01', max(CASE WHEN AreaId='[G]' or AreaId=N'L02' THEN 'X' ELSE ' ' END) as 'L02' from floor, tbuser where FloorUserId= tbuser.userID ) as derivedTable where row_number BETWEEN 1 AND 20
But I keep getting the following error:
The column "FloorId" is invalid in the selection because it is not contained in either the aggregate function or the GROUP BY clause.
source share