MySQL排序字符串作为日期而不是字符串 [英] mysql sort string as date not as string

查看:71
本文介绍了MySQL排序字符串作为日期而不是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承的DB存储的日期如下:yyy-mm-dd hh:mm:ss

The DB I inherited stored there dates like: yyy-mm-dd hh:mm:ss

我希望在mysql查询中按日期排序,但是它将它们当作字符串对待并进行相应的排序.

I was hoping to sort by date in my mysql query but it is treating them like a string and sorting accordingly.

有人知道一种将它们排序为日期而不是查询本身中的字符串的方法吗?

Any one know of a way to sort them as a date and not a string in the query itself?

谢谢,罗伯特

推荐答案

您可以尝试将值转换为日期并按该日期排序:

You can try casting the value to a date and sorting by that:

ORDER BY CAST(SDate As DATETIME);

这篇关于MySQL排序字符串作为日期而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆