Home > Database > Mysql Tutorial > mysql records are output in reverse order according to the date field_MySQL

mysql records are output in reverse order according to the date field_MySQL

WBOY
Release: 2016-08-20 08:48:11
Original
1651 people have browsed it

We know that output in reverse order is very simple

select * from table order by id desc
Copy after login

Just do this

Then the problem now is how to output the date field in reverse order

Here we use cast() to convert the specified field to the type we need

The following is the sql statement in the actual project

select * from water where phoneNumber=@phoneNumber order by cast(date as datetime) desc
Copy after login

We talk about learning without thinking, so let’s think about the deeper content.

After consulting the information, I learned that there are two ways to convert the type

1.cast() method

2.convert() method

Use format

1.cast(field name as data type)

Such as the above sql statement

cast(date as datetime)

2.convert(field name, data type)

Example: convert(da,datetime)

The above is the mysql record output based on the date field in reverse order introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support of the website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template