数码资讯
case表达式实现一个条件逻辑返回一个值。
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
在开发过程中,常常需要基于条件逻辑返回一个列的值,这时我们需要使用case表达式。
例如,下面的查询到产品表使用案例表达的SELECT语句生成信息描述的CategoryID列的值。
SQL代码如下所示:
-设置数据库上下文
tsqlfundamentals2008使用;
去
选择ID、产品名称、CategoryID,
案例CategoryID
当1 then'beverages
当2 then'condiments
当3 then'dairy产品
当4 then'confections
当5 then'grains /谷物
当6 then'meat /家禽
当7 then'produce
当8 then'seafood
else'unkown类别
最后将
从生产、产品;
查询结果:
例如,下面的查询到产品表使用案例表达的SELECT语句生成信息描述的CategoryID列的值。
SQL代码如下所示:
-设置数据库上下文
tsqlfundamentals2008使用;
去
选择ID、产品名称、CategoryID,
案例CategoryID
当1 then'beverages
当2 then'condiments
当3 then'dairy产品
当4 then'confections
当5 then'grains /谷物
当6 then'meat /家禽
当7 then'produce
当8 then'seafood
else'unkown类别
最后将
从生产、产品;
查询结果:
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。