Select only last value using group by at mysql

后端 未结 6 700
有刺的猬
有刺的猬 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:34

    SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(%requiredfield%), ',', count(*)),',',-1)
    

    This will get the last value of the 'required field' from any group_concat, if unsorted it will be the last value in the table by default.

    Could use group_concat_ws to account for possible null fields.

提交回复
热议问题