How to write an SQL statement for sorting the release time and update time

Source: Internet
Author: User
There are two sorting fields, the update time: upTime release time: After the addTime article is published, there will be its release time. If you modify the article, a modification time will be saved. Sort data on the homepage according to the following rules: 1. If an article with an update time uses upTime, only the published time uses ad..., there are two sorting fields,
Update Time: upTime
Release date: addTime

An article will be published after it is published. If it is modified, a modification time will be saved.
Retrieve data on the homepage and sort the data according to the following rules:
1. For articles with Update time, use upTime and only addTime for release time for sorting in order

// The data retrieved in this way is not required. select * from table order by upTime desc, addTime desc

Reply content:

There are two sorting fields,
Update Time: upTime
Release date: addTime

An article will be published after it is published. If it is modified, a modification time will be saved.
Retrieve data on the homepage and sort the data according to the following rules:
1. For articles with Update time, use upTime and only addTime for release time for sorting in order

// The data retrieved in this way is not required. select * from table order by upTime desc, addTime desc

Select * from table order by case when upTime is null then addTime desc else upTime desc end

Maybe you have a problem with your thinking? I think it is dizzy.
At the first release of the articleaddTimeAndupTimeIsn't it? To retrieve data, you only need to useupTimeSorting is fine, because there is noupTimeNoupTimeIn the caseupTimeEqualaddTime.

UpTime = addTime

If not, add a field for sorting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.