[英]SQL option to display the results on evaluating the column values
I have a table as shown below我有一个如下所示的表格
SourceCustomerId源客户 ID | HasTaxBenifit有税收优惠 | HasCollateral有抵押品 | HasLoan有贷款 |
---|---|---|---|
100021 100021 | No不 | No不 | No不 |
100022 100022 | No不 | No不 | Yes是的 |
100023 100023 | No不 | Yes是的 | No不 |
100024 100024 | No不 | Yes是的 | Yes是的 |
100025 100025 | Yes是的 | No不 | No不 |
100026 100026 | Yes是的 | No不 | Yes是的 |
100027 100027 | Yes是的 | Yes是的 | No不 |
100028 100028 | YEs是的 | Yes是的 | Yes是的 |
On Using a select statement, the expected output.在使用 select 语句时,预期的 output。
SourceCustomerId源客户 ID | BinaryTaxBenifit二元税收优惠 | BinaryCollateral二元抵押品 | BinaryLoan二元贷款 |
---|---|---|---|
100021 100021 | 0 0 | 0 0 | 0 0 |
100022 100022 | 0 0 | 0 0 | 1 1 |
100023 100023 | 0 0 | 1 1 | 0 0 |
100024 100024 | 0 0 | 1 1 | 1 1 |
100025 100025 | 1 1 | 0 0 | 0 0 |
100026 100026 | 1 1 | 0 0 | 1 1 |
100027 100027 | 1 1 | 1 1 | 0 0 |
100028 100028 | 1 1 | 1 1 | 1 1 |
The logic is every column has a binary equivalent and they will be having a value of 0 if the columns are having a value 'No'.逻辑是每一列都有一个二进制等价物,如果列的值为“否”,它们的值为 0。 else 'Yes'.否则“是”。 How do I implement this?我该如何实施?
You can use a case
expression:您可以使用case
表达式:
select t.*,
(case when HasTaxBenifit = 'Y' then 1 else 0 end) as BinaryTaxBenefit,
. . .
from t;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.