案例表达
您如何编写具有2个条件的案例表达式?
我试图在下面的代码中说的是颜色是红色的,而质量不好,然后价格不佳。当颜色是红色但质量好时,价格 *2。
质量只有2个选项,即好和坏
代码示例:
Case when color = 'red' and quality = 'Bad' then price
else price * 2
end as RED
How do you write a case expression that has 2 conditions ?
What I'm trying to say in the code below is when the color is red and the quality is bad then price. And when color is red but quality is Good then price *2.
There's only 2 options for quality i.e Good and Bad
Code Example:
Case when color = 'red' and quality = 'Bad' then price
else price * 2
end as RED
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个案例的基本结构:
您可以根据需要(或DBMS支持)拥有尽可能多的“ While/then”行。您可以将任何布尔表达式代替A或B。您可以将任何表达式代替X,Y和Z,包括另一种情况。
因此,您可以简单地列出所有这样的组合:
或者您可以这样嵌套它们:
Here is the basic structure of a CASE:
You can have as many "when/then" lines as you want (or your dbms supports). You can put any boolean expression in place of A or B. You can put any expression in place of X, Y, and Z, including another CASE.
So you could simply list out all your combinations like this:
Or you can nest them like this:
考虑到您的示例:
查看案例的语法...结束可以以不同的方式使用。
或
每个结果(Result1,result2,result0)本身可能是一个案例...结束语句。
Considering your example:
look at the syntax the case ... end can be used in differen ways.
or
each results (result1, result2, result0) may itself be a case ... end statement.