sort table with timestamp field without considering time of day
I have a table in Mysql (firstname,lastname,data1,data2,...) that one field name is MYDATE and ty开发者_JAVA百科pe 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.
I want write a select query that sort this table with (yyyy-mm-dd) and without considering (mm:ss:ms).
ORDER BY date(mydate)
but it will cause fullscan.
Just cast it to a date in your order by clause:
SELECT columns
FROM some_table
ORDER BY CAST(mydate AS date);
select columns
from table_name
order by date_format(date_column, '%Y-%m-%d')
精彩评论