MySQL Custom sort order

Source: Internet
Author: User

MySQL Custom sort order

Example: Adding an ORDER by FIELD (status,3,4,0,2,1) statement to a SQL statement defines the sort order

SELECTtsdvoucher0_. voucher_id asvoucher1_0_, Tsdvoucher0_.comment_device_type ascomment2_0_, tsdvoucher0_.comment_id ascomment3_0_, Tsdvoucher0_.comment_person_no ascomment4_0_, Tsdvoucher0_.comment_pic ascomment5_0_, tsdvoucher0_.comment_spending asComment6_0_, tsdvoucher0_. Create_time asCreate7_0_, tsdvoucher0_. Restaurant_context asRestaurant8_0_, tsdvoucher0_. restaurant_id asRestaurant9_0_, tsdvoucher0_. Restaurant_name asrestaurant10_0_, tsdvoucher0_.user_id  asUser11_0_, tsdvoucher0_. VERSION asVersion0_, tsdvoucher0_. voucher_act_id asVoucher13_0_, tsdvoucher0_. Voucher_act_ratios asVoucher14_0_, tsdvoucher0_. Voucher_business_status asvoucher15_0_, tsdvoucher0_. Voucher_check_status asVoucher16_0_, tsdvoucher0_. Voucher_checked_time asVoucher17_0_, tsdvoucher0_. Voucher_denomination asVoucher18_0_, tsdvoucher0_. Voucher_pic asVoucher19_0_, tsdvoucher0_. Voucher_used_time asvoucher20_0_, tsdvoucher0_. Voucher_valid_day asvoucher21_0_ fromT_sd_voucher tsdvoucher0_WHEREtsdvoucher0_.user_id = ?ORDER  byFIELD (tsdvoucher0_. Voucher_business_status,3,4,6,5), FIELD (tsdvoucher0_. Voucher_check_status,3,2,4), tsdvoucher0_. Create_timeASC


Description: Status is a sort field, followed by the related value of the field

Related Article

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.