使用时间戳字段排序表而不考虑时间

时间:2022-11-30 11:51:22

I have a table in Mysql (firstname,lastname,data1,data2,...) that one field name is MYDATE and type of this field is timestamp. In this field, the date saved as (yyyy-mm-dd mm:ss:ms), and there are many records of this table.

我在Mysql(firstname,lastname,data1,data2,...)中有一个表,一个字段名是MYDATE,该字段的类型是时间戳。在此字段中,日期保存为(yyyy-mm-dd mm:ss:ms),并且此表有许多记录。

I want write a select query that sort this table with (yyyy-mm-dd) and without considering (mm:ss:ms).

我想编写一个select查询,用(yyyy-mm-dd)对此表进行排序,而不考虑(mm:ss:ms)。

3 个解决方案

#1


7  

ORDER BY date(mydate)

but it will cause fullscan.

但它会导致全扫描。

#2


3  

Just cast it to a date in your order by clause:

只需按顺序将其转换为您的订单中的日期:

SELECT columns
FROM some_table
ORDER BY CAST(mydate AS date);

#3


2  

select columns
from table_name
order by date_format(date_column, '%Y-%m-%d')

#1


7  

ORDER BY date(mydate)

but it will cause fullscan.

但它会导致全扫描。

#2


3  

Just cast it to a date in your order by clause:

只需按顺序将其转换为您的订单中的日期:

SELECT columns
FROM some_table
ORDER BY CAST(mydate AS date);

#3


2  

select columns
from table_name
order by date_format(date_column, '%Y-%m-%d')