Freelancer: ammarikhlaq1
Jaa:
Tee ilmoitus työstä

Sql Query

Partition by is more efficient than group by plus joining to table with million of records to itself for getting vehicle's latest position doesn't make sense

Kilpailutyö #3 kilpailussa                                                 MySQL query optimization

Julkinen selvennystaulu

  • andreshg112
    Kilpailun järjestäjä
    • 4 vuotta sitten

    I'm getting error:

    # Entry 3
    select * from vehicles v inner join (select *,
    row_number() over (partition by vehicle_id order by time desc) as rn
    from positions
    where rn = 1) p
    on v.id = p.vehicle_id
    and p.speed > 5;

    [2019-06-17 14:46:07] [42000][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 '(partition by vehicle_id order by time desc) as rn
    [2019-06-17 14:46:07] from positions
    [2019-06-17 14:46:07] having' at line 4

    • 4 vuotta sitten