开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜