drop TEMPORARY table if exists idss;
CREATE TEMPORARY TABLE `idss` (
`id` INT(11) NULL DEFAULT NULL,
`tag` VARCHAR(50) NULL DEFAULT NULL
);
INSERT INTO `idss` (`id`, `tag`) VALUES
(1, 'a-1'),
(2, 'a-2'),
(3, 'a-3'),
(4, 'a-9'),
(5, 'a-7'),
(6, 'a-8'),
(7, 'a-4'),
(8, 'a-5'),
(9, 'a-6'),
(13, 'c-3'),
(14, 'c-4'),
(15, 'c-2');
select *,
substring(tag, 1, 1) 'Letter',
ASCII(substring(tag, 1, 1)) 'Letter_As_ASCII_code',
CAST(substring(tag, 3, length(tag)) AS SIGNED) 'LastDigit'
from idss
order by Letter_As_ASCII_code, LastDigit