Forum Discussion

rsbin's avatar
rsbin
Community Champion
2 years ago
Solved

Off Topic: Need help with SQL Query

Good Day, Hoping to get some help with a SQL Query.  My SQL guy recently left, and I don't as yet have an account on any of the other help sites.  So hoping someone here can lend some guidance.  Ha...
  • Daniel29195's avatar
    Daniel29195
    2 years ago

    rsbin 

    SELECT 

    DeviceID,
    ModifiedDate,
    OBDOdometerMeters,
    UTCOBDOdometerMetersDate

    from ( 
    SELECT
    DeviceID,
    ModifiedDate,
    OBDOdometerMeters,
    UTCOBDOdometerMetersDate,
    ROW_NUMBER() OVER (PARTITION BY DeviceID ORDER BY ModifiedDate DESC ,  UTCOBDOdometerMetersDate desc ) AS RowNum
    FROM
    YourTableName 
    )  as a 

     

    WHERE
    RowNum = 1;

     

     

    the previous should work.  

    however you can try this approach ( using nested selected query ) .

     

    let me know if this helps .

     

     

    If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠