MySQL Cookbook
Problem
You want to sort a set of values using one or more substrings of each value. Solution
Extract the hunks you want and sort them separately. Discussion
This is a specific application of sorting by expression value (see Section 7.2). If you want to sort rows using just a particular portion of a column's values, extract the substring you need and use it in the ORDER BY clause. This is easiest if the substrings are at a fixed position and length within the column. For substrings of variable position or length, you may still be able to use them for sorting if there is some reliable way to identify them. The next several recipes show how to use substring extraction to produce specialized sort orders. |
Категории