Sql time to sort varchar format

Use the sort function of time:

STR_TO_DATE (time field name, '% Y-% m-% d') DESC;

 

Question: varchar format field sort, not sorted in chronological order

select * from test order by stat_date desc

 

 Solution: need to convert the format to date format

select * from test order by  STR_TO_DATE(stat_time, '%Y-%m-%d') desc

 

Guess you like

Origin www.cnblogs.com/cailingsunny/p/11913457.html