我想要建立视图,或者只是从数据库中获取一些数据,但要以特定的方式。
例如,如果数据是:
1 | test | test | 0 | test
2 | test | test | 1 | test
3 | test | test | 1 | test
4 | test | test | 1 | test
5 | test | test | 0 | test产出应是:
1 | test | test | FALSE | test
2 | test | test | TRUE | test
3 | test | test | TRUE | test
4 | test | test | TRUE | test
5 | test | test | FALSE | test有什么想法吗?
发布于 2016-06-20 12:57:16
使用CASE表达式。
查询
SELECT col1, col2, col3,
CASE col4 WHEN 0 THEN 'False'
WHEN 1 THEN 'TRUE'
ELSE NULL END AS col4, col5
FROM your_table_name;发布于 2016-06-20 12:57:08
SQL中的if条件使用 expression表示。
SELECT
id
, a
, b
, CASE c WHEN 0 THEN 'FALSE' ELSE 'TRUE' END AS c
, d
FROM my_table注意,Server中有两种形式的CASE表达式--简单的和搜索的。以上是一个简单的例子。
发布于 2016-06-20 13:00:28
如果是2012+,则可以使用内联
IIF(condition,a,b)https://stackoverflow.com/questions/37923139
复制相似问题