For sorting questions, consult experts.

Source: Internet
Author: User
For sorting questions, consult experts. This post was last edited by xviphackl at 16:14:18

The development process encountered a very tangled problem.

That is, I want to move the newly published content or content in any location in the entire content list to the position specified in the content list! For example:

Order id
---------------
4 1
3 2
2 3
1 4


I want to move the data with ID 4 to the data with ID 2. My current solution is to sort by ORDER + 1 (-1) of the target ID. However, the same value of ORDER will appear in an ordered list like this, at this time, the final result of sorting is somewhat unexpected.


Is there any way to solve this problem?


Reply to discussion (solution)

Order by 'order', id
Sort by id with the same order
As long as you follow your agreement, there will be no unexpected results




For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?



For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?

Desc is in descending order. it is arranged in descending order. of course 10 is placed in front of 1, and the role_id uses asc.

There is a lot of content in a table. we need to put some self-considered important content through human intervention, so that he can reach the specified position !!!

There are no rules, so he is free to "move" and "move down. The DISCUZ sorting is different for you. we now consider a field with no type differentiation. Only the size of the number is used to determine the position of the content.


This should be the case. it's messy.





For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?

Desc is in descending order. it is arranged in descending order. of course 10 is placed in front of 1, and the role_id uses asc.



OK,
SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` ASC


Do you mean this.

On the contrary, I want to route ID 10 to ID 1. what should I do? I cannot change the SQL statement all the time?






For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?

Desc is in descending order. it is arranged in descending order. of course 10 is placed in front of 1, and the role_id uses asc.



OK,
SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` ASC


Do you mean this.

On the contrary, I want to route ID 10 to ID 1. what should I do? I cannot change the SQL statement all the time?

If you want to manually specify a function, write a function. if you want 10 to be above 1, upload 10 to this function, and set 10 to above when it is displayed, 1 is the same as above. That is to say, control the display.







For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?

Desc is in descending order. it is arranged in descending order. of course 10 is placed in front of 1, and the role_id uses asc.



OK,
SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` ASC


Do you mean this.

On the contrary, I want to route ID 10 to ID 1. what should I do? I cannot change the SQL statement all the time?

If you want to manually specify a function, write a function. if you want 10 to be above 1, upload 10 to this function, and set 10 to above when it is displayed, 1 is the same as above. That is to say, control the display.


The key is how to determine the top and bottom. This is a problem ,? Can you tell me your specific method?








For example, I want to route the data whose role_id is 1 to 10, but the result is unexpected.

SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` DESC 


Can I change an SQL statement once when this problem occurs?

Desc is in descending order. it is arranged in descending order. of course 10 is placed in front of 1, and the role_id uses asc.



OK,
SELECT * FROM  `tbl` ORDER BY  `role_sort` DESC ,  `role_id` ASC


Do you mean this.

On the contrary, I want to route ID 10 to ID 1. what should I do? I cannot change the SQL statement all the time?

If you want to manually specify a function, write a function. if you want 10 to be above 1, upload 10 to this function, and set 10 to above when it is displayed, 1 is the same as above. That is to say, control the display.


The key is how to determine the top and bottom. This is a problem ,? Can you tell me your specific method?

This depends on your own rules. Aren't you going to use human intervention to bring "self-think" important content to a specific position? Then you have to clarify the rules before you can code the rules. Do you understand?

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.