I have sql query below but i face a problem when execute 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:
Column 'FloorId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Perhaps this may help you to get where you want:
Select
row_number() OVER (PARTITION BY userid Order By user.Id) as 'row_number', user.Id,
max(CASE WHEN floor.AreaId='[G]' or floor.AreaId=N'L01' THEN 'X' ELSE ' ' END) as 'L01',
max(CASE WHEN floor. AreaId='[G]' or floor.AreaId=N'L02' THEN 'X' ELSE ' ' END) as 'L02'
from
floor
JOIN
user ON floor. = user. --what?
where
user.Id = userID
group by
user.Id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With