MySQL ORDER BY statement, infinite classification problem

Source: Internet
Author: User

Teacher please help to see?
How to reorder the siblings in an infinite 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 because order by requires that the second column be used only if the first column is the same when sorting by more than one column. But the first group of FullPath is unlikely to be the same. Now how to achieve such as red wine sub-category red wine 1 and red wine 2 of these two re-implementation sort.
Asking for advice.

Reply content:

Teacher please help to see?
How to reorder the siblings in an infinite 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 because order by requires that the second column be used only if the first column is the same when sorting by more than one column. But the first group of FullPath is unlikely to be the same. Now how to achieve such as red wine sub-category red wine 1 and red wine 2 of these two re-implementation sort.
Asking for advice.

I took a closer look at the problem.

Now the first field is the parent ...
It takes only a single brain to get all the categories out, and then use the dynamic language to sort them out.

Old Answer:

Add a field father , red wine 1 and red wine 2 are father 0-12-16 , you can.

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

The effect of this remark

In fact, I do not know that the problem is ultimately to solve the problem, what the demand is not clear.
If you want to sort output two-level classifications on a page, that's 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.