2015년 11월 23일 월요일

Mysql select case statement


When the field of table is stated by integer like code,
it is hard to undertand what it means immediately.
so that you can use select case statement in mysql.

SELECT
id,
CASE
code
WHEN '1' THEN 'start'
WHEN '2' THEN 'stop'
ELSE
code
END
FROM test_table;

If field data is 1, it shows 'start',
if field data is 2, it shows 'stop',
if field is not 1 nor 2, it show origin data of code.

댓글 없음 :

댓글 쓰기