Select most recent row with GROUP BY in MySQL

后端 未结 6 2019
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 03:26

I\'m trying to select each user with their most recent payment. The query I have now selects the users first payment. I.e. if a user has made two payments and the paym

6条回答
  •  自闭症患者
    2020-12-09 03:46

    My solution:

    SELECT
    
    u.codigo, 
    u.nome,  
    max(r.latitude),  
    max(r.longitude),  
    max(r.data_criacao) 
    
    from TAB_REGISTRO_COORDENADAS  r
    
    inner join TAB_USUARIO u
    
    on u.codigo = r.cd_usuario
    
    group by u.codigo
    

提交回复
热议问题