I have an int
column that contains values no larger than about 20. I want to select as its corresponding upper case letter of the alphabet:
1 = A 2 = B 3 = C ...
I don’t care what happens after Z because the column doesn’t contain larger values. Is there a simple way to do this with a SQL query, to convert to a single-byte character like this?
Advertisement
Answer
Add 64 to your integer and you have the ASCII value of the letter you want.
mysql> select CHAR(1+64); +------------+ | CHAR(1+64) | +------------+ | A | +------------+
Read https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char