gpt4 book ai didi

sql - 存储过程列值由另一列的值确定

转载 作者:行者123 更新时间:2023-12-02 08:59:48 26 4
gpt4 key购买 nike

我有一个类似这样的数据表。

date, amount, price
2009-10-12, 20, 15.43
2009-10-13, -10, 6.98

我需要编写一个存储过程来返回这些列,并创建一个新列来指示金额是正数还是负数。因此该过程的最终结果将如下所示。

date, amount, price, result
2009-10-12, 20, 15.43, positive
2009-10-13, -10, 6.98, negative

如何做到这一点?这是一个 sql 2008 ent 数据库。

最佳答案

select  date, 
amount,
price,
case when amount > 0 then 'positive'
when amount < 0 then 'negative'
end as positive_or_negative
from #table

关于sql - 存储过程列值由另一列的值确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2187548/

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