How to transform a field in a sql statement?
I want to transform a field from my SQL Query, depending on the value of that field.
For example, if a field called "class" has a value of 1, the output should be "First Class". What can I do in SQL to make it bring back "First Class" instead of 1 in my resul开发者_JS百科t set?
SELECT CASE WHEN col1 = 1 THEN 'first class'
ELSE 'second class' -- or whatever you want to output in the != 1 case
END as TransformedColumn,
col2,
-- etc...
FROM myTable
精彩评论