-2

i have value from database, when the data show 1, it will be a, when the data show 2, it will be b, ....

CREATE TABLE `jurnal`(
`id` INT(11)NOT NULL AUTO_INCREMENT,
`month` INT(2)NOT NULL,
`year` INT(4)NOT NULL,
PRIMARY KEY(`id`))ENGINE = INNODB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8;

the value from database like:

id=1 month=3 year=2012

i want make the value from month using 'if else' if work, to make

if 1, it will be a, if 2, it will be b, ... and so on to 12

the output data that I wish would like

c, 2012 not 3, 2012

thank's before

4

2 回答 2

2

您始终可以使用该CHAR函数渲染出您喜欢的任何字符:

SELECT CHAR(96 + month)

ASCII 97 是a.

于 2012-11-26T17:18:17.207 回答
0

如果你想在你的条件中添加一些逻辑,你可以使用 CASE

SELECT CASE month WHEN 1 THEN 'a' WHEN 2 THEN 'b' ELSE '?' END; FROM jurnal

http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html

谢谢

于 2012-11-26T17:27:35.117 回答