mysql按strotime排序(列)asc可能吗?

toiithl6  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(270)

我有一个关于varchars的专栏,比如2.7.2019 10:15-12:30。我现在想对这些日期的输出进行排序,但需要将它们格式化为时间戳。我怎么能在晚上做到呢 ORDER BY 'column' . 这是我目前的尝试: mysqli_query($conn, "SELECT * FROM ".$kTable." WHERE class='".$class."' ORDER BY '.strtotime(.''datehours''.).' DESC"); 我知道varchars包含一系列时间戳,但是为了排序,它可以完成这项工作。像2018年12月12日10:00-12:15这样的范围将是2018年12月12日22:15,并且将具有更高或更低的值,比如10:10-12:15(22:25)

o4tp2gmn

o4tp2gmn1#

你可以用 str_to_date() 要将范围的第一部分转换为日期时间:

select . . .  -- whatever you want to select here
from t
order by str_to_date(substring_index(datehour, '-', 1), '%d.%m.%Y %H:%i')

或是任何适合你专栏的格式。

相关问题