本文介绍了如何在Sql查询中使用案例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询在下面



当Business_Group喜欢''%Back Office%''然后奖金作为支持其他奖金结束为ALC

my query is below

case when Business_Group like ''%Back Office%'' then bonus as Support else bonus end as ALC

推荐答案

case when Business_Group like '%Back Office%' then bonus else bonus end as ALC





但这是你的事从来没有想要的结果,我相信。你的逻辑应该是

- 如果Business_Group包含像''Back Office'这样的文本,那么返回结果奖励作为ALC

- 如果不是则返回不同的结果结果专栏ALC



确保你正确理解大概时间......。

参考: []



希望,它有帮助:)





根据OP的评论,解决方案查询应该看起来像 -



But this is something you never want as result, what I believe. Your logic should be
--if Business_Group contains text like ''Back Office'' then return bonus in result as ALC
--if not then return different result for result column ALC

Make sure that you understand "case when..." correctly.
Reference: CASE in SQL Server[^]

Hope, it helps :)


As per the comment by OP, the solution query should look like-

select case when Business_Group like '%Back Office%' then bonus else NULL end as Support,case when Business_Group like '%Back Office%' then NULL else bonus end as ALC





我相信可以有更好的方法来做到这一点但是如果您想要使用case when ..的解决方案,这可以提供帮助。



如果它没有用,请告诉我。



I beleive there can be a better way to do this but as you wanted the solution using "case when..", this can help.

Please let me know if it doesn''t help.



这篇关于如何在Sql查询中使用案例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:19
查看更多