There is a string, sort the letters (characters) of the string alphabetically.
Example:
SET @var="acb"; SELECT @var; SELECT SORT(@var); Conclusion:
acb @var;
abc SORT(@var);
We will need a worksheet with ordinal numbers from 1 to the maximum length of the line being processed:
create table seqnum(X int not null, primary key(X)); insert into seqnum values(1),(2),(3),(4); insert into seqnum select X+4 from seqnum; insert into seqnum select X+8 from seqnum; insert into seqnum select X+16 from seqnum; insert into seqnum select X+32 from seqnum; ... The sorting query will look like this:
SET @var="acb"; select group_concat(substr(@var,x,1) order by substr(@var,x,1) separator '') from seqnum where x<=length(@var); This query first expands the input string into individual characters, one per record, and then collects the resulting sample back into the string, but in the specified order.
Source: https://ru.stackoverflow.com/questions/617549/
All Articles
SET @var=СОРТ("авб"); - Los Pollos Hermanos