博客
关于我
SQL 选择列 IF表达式,Contains表达式的用法
阅读量:414 次
发布时间:2019-03-06

本文共 508 字,大约阅读时间需要 1 分钟。

因为业务需要需要使用到, 列中的字段或根据列值是否满足某一条件,进行输出。比如类似与  select if()  ……from……;(但是SQL Server 没有 if 表达式)

比如,如果Score>60 且 Score<70 则输出合格,用case when ……then……else……end

如果是contains 条件,比如类似   select if(contains('aaa'))   …… from…… 则需要用 charindex 进行转化

接下来看看怎么达到  if 表达式效果:

熟悉一下case 用法

select case when  1>2 then '1大于2' else '1小于2' end;

输出   1小于2

charindex 用法(可以当作Contains 或like 用

-- 单个字符select charindex('a','123ab123')-- 字符串select charindex('ab','123ab123')

然后结合起来就达到相应效果了

select case when charindex('a','123a123')>1 then 1 else 2 end;

 

转载地址:http://yovkz.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>