Wrong test case? Potential solution with and without variable

  • 0

    I have potential 2 solutions but just couldn't pass the 130 vs 150 test case and wonder how the accepted solution got accepted and how this test case can be right?
    1_1497847578351_Screen Shot 2017-06-18 at 9.42.59 PM.png 0_1497847578351_Screen Shot 2017-06-18 at 9.41.13 PM.png

    my solution with variable and without variable

    select t1.Id,t1.month as Month, t1.Salary as Salary from
    (select e1.Id, e1.month, (case when @cur_id != e1.Id then @sal:=e1.salary else @sal:=@sal+e1.salary end) as Salary, 
    @cur_id:=e1.Id from Employee e1 JOIN (select @cur_id:='', @sal:=0) t2 Order by e1.Id, e1.month) t1,
    (select Id, max(month) as month from Employee group by Id) t2
    where t1.Id=t2.Id and t1.month != t2.month
    order by Id, Month desc
    without variable
    select e.Id, e.month as Month, sum(e1.salary) as Salary from Employee e join Employee e1 
    ON e.Id=e1.Id and e.month>=e1.month,
    (select Id, max(month) as month from Employee group by Id) t1
    where e.Id = t1.Id and e.month != t1.month
    group by e.Id, e.month order by e.Id, e.month desc

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.