gpt4 book ai didi

sql - 使用 if else 创建 View

转载 作者:行者123 更新时间:2023-12-01 07:35:47 26 4
gpt4 key购买 nike

我想制作 View 或只是以特定方式从数据库中获取一些数据。

例如,如果数据是:

 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

有什么想法吗?

最佳答案

使用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;

关于sql - 使用 if else 创建 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com