How to achieve this sort

Source: Internet
Author: User
How to sort the items added to the item list in this way and there are stock options in the shelving status by default, with fewer or zero stock options at the back of the list. Goods_id is auto-incrementing. The largest one is the latest one. Inventory Field: is_on_sale1: 0 for mounting is the number of dismounted Inventories: goods_number & nbsp; how can I write SQL statements? how can I sort ORDERBY 'is _?
The newly added items in the product list are in the shelving status, and the items with stock options are listed first by default. the items with less stock or zero stock are listed later.
Goods_id is auto-incrementing. The largest one is the latest one. Inventory Field: is_on_sale 1: shelving 0: dismounting stock quantity: goods_number

How can I write SQL statements?

------ Solution --------------------
Order by 'is _ on_sale' DESC, 'goods _ id' DESC, 'goods _ number' DESC
------ Solution --------------------
Order by is_on_sale desc, goods_number desc, goods_id desc


Order by can be used multiple times, and priority is sorted in order,
Is_on_sale is 1 on the top, and dismounted on the bottom
Goods_number comes first in the sorting result above,
Goods_id in the previous results, the new in the same condition is at the beginning

------ Solution --------------------
G. is_on_sale desc
So the shelving and inventory of 0 will also appear in front of the dismounting
If you don't want this to happen, you need to add judgment conditions.
G. is_on_sale and g. goods_number> 0 desc
And so on

You should test various situations in SQL manager before writing code.

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.