开发者

How to transform a field in a sql statement?

开发者 https://www.devze.com 2023-02-28 12:09 出处:网络
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

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

精彩评论

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

关注公众号