My accepted solution using EXISTS

  • 1

    select round(sum(i1.TIV_2016), 2) as TIV_2016
    from insurance i1
    where EXISTS (select *
    from insurance i2
    where i1.PID <> i2.PID and i1.TIV_2015 = i2.TIV_2015)
    and NOT EXISTS(select *
    from insurance i3
    where i1.PID <> i3.PID and i1.LAT = i3.LAT and i1.LON = i3.LON)

  • 0

    select sum(i1.TIV_2016) as TIV_2016 from insurance i1 where
    exists (select*
    from insurance i2
    where i1.PID<>i2.PID and i1.TIV_2015 =i2.TIV_2015
    and (i1.LAT<>i2.LAT or i1.LON<>i2.LON))

    Could you explain why this similar code would fail?

Log in to reply

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