Mysqlorderby statement, unlimited classification problem

Source: Internet
Author: User
Tags what sql
Could you help me? How can I re-sort the same-level classes in an unlimited category? {code ...} fullpath is sorted, but orderby requires that the second column be used only when the first column is the same when multiple columns are sorted. However, the first group of fullpath cannot be the same. Excuse me...

Could you help me?
How to re-sort the same-level categories in an unlimited category

SELECT `DishCategory_Path`,`DishCategory_Name`,`DishCategory_Sort`,concat(`DishCategory_Path`,'-',id) as fullpath from chi_category order by fullpath asc,`DishCategory_Sort`asc


Fullpath is sorted, but order by requires that the second column is used only when the first column is the same. However, the first group of fullpath cannot be the same. How can we sort lower-level red wine 1 and red wine 2.
Ask for advice

Reply content:

Could you help me?
How to re-sort the same-level categories in an unlimited category

SELECT `DishCategory_Path`,`DishCategory_Name`,`DishCategory_Sort`,concat(`DishCategory_Path`,'-',id) as fullpath from chi_category order by fullpath asc,`DishCategory_Sort`asc


Fullpath is sorted, but order by requires that the second column is used only when the first column is the same. However, the first group of fullpath cannot be the same. How can we sort lower-level red wine 1 and red wine 2.
Ask for advice

I took a closer look at the problem.

The first field is the parent level...
You only need to extract all the categories in one brain and sort them in Dynamic Language.

Old answer:

Add another fieldfather, Red wine 1 and red wine 2fatherAll0-12-16.

SELECT DishCategory_Path,DishCategory_Name,DishCategory_Sort,      concat(DishCategory_Path,'-',id) as fullpath from chi_category order by concat(DishCategory_Path,'-',DishCategory_Sort)

Effect of this sentence

In fact, I don't know what the problem is ultimately to solve, and what the demand is.
If you want to output the secondary classification by sorting on the page, it is not what SQL does.

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.