Sorting and sorting algorithms

Source: Internet
Author: User

Sorting and sorting algorithms

-- Sorting problems, such as numbers 1, 2, 3, 4, 5, and 6 -- ideas: (1) if 1 is changed to 5, that is, 1 is directly changed to, 2, 3, 4, and 5, respectively, minus 1 and 6 unchanged -- (2) if 5 is changed to 3, 5 is directly changed to and 2, 3, 4 minus 1, 6 unchanged -- (3) for example: 3 to 6, then 6 is the target value, 3 is the value to be the target -- (4) implement with transactions or stored procedures -- (5) the parameters to be passed are: Table Name, target value, value to be the target, and Create proc [dbo] in the ID column. [pro_woqu] @ ID int, -- ID value @ targetValue int, -- target value @ wishtargetValue int, -- value to be the target @ tableName varchar (100) asbegin tranupdate [User] set DisplayOrder = @ targetValue where ID = @ ID; if (@ targetValue <@ wishta RgetValue) -- if 5 is changed to 3, 5 is changed to 3, 1, and 2, 3, 4 minus 1, 6 unchanged begin update [User] set DisplayOrder = DisplayOrder + 1 where DisplayOrder >=@ targetValue and DisplayOrder <@ wishtargetValue and ID! = @ ID and ParentID = 0 endif (@ targetValue> @ wishtargetValue) -- 3 to 6, then 6 is the target value, 3 is the value of beginupdate [User] set DisplayOrder = DisplayOrder-1 where DisplayOrder <= @ targetValue and DisplayOrder> @ wishtargetValue and ID! = @ ID and ParentID = 0 endif @ error <> 0 begin rollback tranreturn 0 endelse begin commit tranreturn 1end


What is the difference between the SQL sort statement desc and ASC?

DESC indicates descending order (that is, descending order)
Use ACS to sort data in ascending order (Ascending Order)

What is the difference between the SQL sort statement desc and ASC?

DESC indicates descending order (that is, descending order)
Use ACS to sort data in ascending order (Ascending Order)

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.