我试图返回"增加调整"或者"减少调整"取决于"金额"列为正面或负面。
2.8.7
任何建议都将不胜感激......
编辑:整个选择=:
CASE amount
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
答案 0 :(得分:0)
怎么样:
CASE
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
答案 1 :(得分:0)
因为你用
开始你的陈述CASE amount
您在数量上指定了一个简单的CASE表达式,这意味着WHEN子句只能是等式检查。尝试搜索表达式:
CASE
when amount > 0 then "Increase Adjustment"
when amount < 0 then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
更多信息:https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql?view=sql-server-2017
答案 2 :(得分:0)
CASE
when amount > '0' then "Increased Adjustment"
when amount < '0' then "Decreased Adjustment"
else "ERROR"
end as
transaction_type
答案 3 :(得分:0)
select tx_date, bank_account, description, amount, currency,
CASE
when bank_account ='CAD-FTX' then 'Suspense_CAD'
when bank_account = 'USD-PRO' then 'Suspense_USD'
when bank_account = 'CAD-PRO' then 'Suspense_CAD'
when bank_account = 'USD-ALL' then 'Suspense_USD'
when bank_account = 'TD-USA' then 'Suspense_USD'
end suspense_account,
CASE
when cast(amount as float) > 0 then 'Increase Adjustment'
when cast(amount as float) < 0 then 'Decreased Adjustment'
end
transaction_type
from [sys_tx_combined]
答案 4 :(得分:0)
这是编写表达式的更简单方法:
select tx_date, bank_account, description, amount, currency,
(case when bank_account in ('CAD-FTX', 'CAD-PRO')
then 'Suspense_CAD'
when bank_account in ('USD-PRO', 'USD-ALL', 'TD-USA')
then 'Suspense_USD'
end) suspense_account,
(case when amount > 0 then 'Increase Adjustment'
when amount < 0 then 'Decreased Adjustment'
end) as transaction_type
from [sys_tx_combined];
注意:
case
表达式进行此类映射时,我更喜欢为每个输出条件设置一个条件,而不是每个输入都有一个条件。cast(amount as float)
几乎肯定不是必需的,所以我将其删除了。