Due to business requirements, several sorting fields are added to the product table. However, the default value of the sorting field (sort) is 0. After a few days, the field value operation of some products has already set the sort value in the background, however, when the remaining products whose sort value is 0 are searched, what logic is used for sorting...
Due to business requirements, several sorting fields are added to the product table. However, the default sorting field (sort) value is 0.
Then, after a few days, the field value operation of some products has already set the sort value in the background, but what logic is the sorting of the remaining products whose sort values are still 0 during retrieval?
PS:auto_id
Yesprimary keyid
Is the unique product number randomly generated by php.
SELECT id,title,auto_id,web_sort FROM `route` WHERE class = 2 AND `status` = 1 AND product_library = 0 ORDER BY web_sort DESC;
Reply content:
Due to business requirements, several sorting fields are added to the product table. However, the default sorting field (sort) value is 0.
Then, after a few days, the field value operation of some products has already set the sort value in the background, but what logic is the sorting of the remaining products whose sort values are still 0 during retrieval?
PS:auto_id
Yesprimary keyid
Is the unique product number randomly generated by php.
SELECT id,title,auto_id,web_sort FROM `route` WHERE class = 2 AND `status` = 1 AND product_library = 0 ORDER BY web_sort DESC;
It should be said that it is based on the primary key order, because the physical order of the data in this table, the query is generally in order to traverse the table. But it's strange why your query results are messy. I tried it locally and it's all in the primary key order.
If you really need a special second sorting requirement, you can add the second sorting rule in the query statement. For example, the sequence is ASC of auto_id:
SELECT id,title,auto_id,web_sort FROM `route` WHERE class = 2 AND `status` = 1 AND product_library = 0 ORDER BY web_sort DESC, auto_id ASC;