Home > Backend Development > PHP Tutorial > Regarding the issue of sorting by specified rules in the database

Regarding the issue of sorting by specified rules in the database

WBOY
Release: 2016-08-04 09:21:43
Original
920 people have browsed it

The database has a column store that stores the names of malls. Now I want the mall to be Taobao, with Amazon ranked first. The other malls are sorted by data creation time, and paging is required.
There is a solution
MySQL provides a method of sorting by field, but filed must include all mall types that already exist in the database, otherwise the ones not included will disrupt the sorting, but the malls under the store (such as Nichia, etc.) will be successively added increase, so this sql statement will continue to change. So I wanted to ask if there are any good solutions.
2 Add a field corresponding to the digital ID of the store, and sort by the digital ID. However, the product now wants Taobao and Amazon to be ranked first, but Chao Lingxi wants Nichia to be ranked first. Wouldn’t this logic be disrupted?
Please tell me if you have any good plans.

Reply content:

The database has a column store that stores the names of malls. Now I want the mall to be Taobao, with Amazon ranked first. The other malls are sorted by data creation time, and paging is required.
There is a solution
MySQL provides a method of sorting by field, but filed must include all mall types that already exist in the database, otherwise the ones not included will disrupt the sorting, but the malls under the store (such as Nichia, etc.) will be added one after another. Increase, so this sql statement will continue to change. So I wanted to ask if there are any good solutions.
Second, add a field corresponding to the digital ID of the store, and sort by the digital ID. However, the product now wants Taobao and Amazon to be ranked first, but Chaolingxi wants Nichia to be ranked first. Wouldn’t this logic be disrupted?
Please tell me if you have any good plans.

This question requires two fields: one is weight and the other is sort.
You look like this

  1. Taobao: weight: 100 sort: 1,

  2. Amazon: weith: 100 sort: 2,

  3. 日亚: weight: 100 sort: 3

  4. Others: weight: 1 sort: 1

  5. ...

Your sql is written like this: select * from table order by weight * sort, this solves the problem. If you want to change permissions, you can adjust weight or sort

Complex logical sorting should not be done at the database level, but should be placed at the code level, such as in a sortable array or map. Just define the sorting rules yourself. JDK has many sorted arrays and maps

Related labels:
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