Select only last value using group by at mysql

后端 未结 6 709
有刺的猬
有刺的猬 2020-12-11 15:16

I have one table with data about attendance into some events. I have in the table the data of the attendance everytime the user sends new attendance, the information is like

6条回答
  •  被撕碎了的回忆
    2020-12-11 15:29

    SELECT id_branch_channel, id_member, attendance, timestamp, id_member 
    FROM (select * from view_event_attendance order by timestamp desc) as whatever
    WHERE id_event = 782 
    GROUP BY id_event,id_member;
    

    EDIT: This may yield better performance:

    SELECT *
    FROM (SELECT id_branch_channel, id_member, attendance, timestamp, id_member 
          FROM view_event_attendance 
          WHERE id_event = 782 
          ORDER BY timestamp desc
         ) as whatever
    GROUP BY id_event,id_member;
    

    As long as the result-set can fit into the Innodb_buffer_pool, you will not see a significant performance drop.

提交回复
热议问题