select aa.datetemp,max(aa.datetime) from (select date_format(datetime,'%Y-%m-%d') datetemp,datetime from tb ) aa group by aa.datetemp