WITH temp_user AS (
SELECT * ,ROW_NUMBER() over (partition by departmentName order by failureTime desc ) as 'row_number'
from user )
SELECT * from temp_user where row_number <= 2
I have sql syntax ,error 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<= 2' at line 4
I want to group by department ,then get every group top 2 user. thank you I change the describe ,then i get the right result .but i don't know why the first sql can't work .
select * from (
SELECT * ,ROW_NUMBER() over (partition by departmentName order by failureTime desc ) as 'row_number'
from user ) as b where b.row_number <=2