求个 sql 语句 数据 简单点的。。
时间:2011-11-16
来源:互联网
怎么查询 包含 18 和 15 的这2个 数字 的 数据
我开始用 like 18%15 这样查询 是可以的
但发觉 15%18 就不行。。。
怎么查呢??
作者: qunqingkai3 发布时间: 2011-11-16
where charindex(',15,',','+col+',') > 0 and charindex(',18,',','+col+',') > 0
作者: AcHerat 发布时间: 2011-11-16
在 数据库 有个这样的 数据 18,15,16
怎么查询 包含 18 和 15 的这2个 数字 的 数据
我开始用 like 18%15 这样查询 是可以的
但发觉 15%18 就不行。。。
怎么查呢??
select * from tb
where ','+col+',' like '%,' + '18' + ',%' and ','+col+',' like '%,' + '15' + ',%'
作者: dawugui 发布时间: 2011-11-16
作者: qianjin036a 发布时间: 2011-11-16
select * from tb where charindex(',18,',col1)>0 and charindex(',15,',col1)>0
作者: pengxuan 发布时间: 2011-11-16
where charindex(',' + '18' + ',' , ','+col+',') > 0
and charindex(',' + '15' + ',' , ','+col+',') > 0
作者: dawugui 发布时间: 2011-11-16
SQL code
select * from tb where charindex(',18,',','+col1+',')>0 and charindex(',15,',','+col1+',')>0
作者: pengxuan 发布时间: 2011-11-16
col like ',15,' or col like ',18,'
作者: fredrickhu 发布时间: 2011-11-16
where ','+ltrim(col)+',' like ',15,' or col like ',18,'
作者: fredrickhu 发布时间: 2011-11-16
where ','+ltrim(col)+',' like ',15,' or ','+ltrim(col)+',' like ',18,'
作者: fredrickhu 发布时间: 2011-11-16
作者: AcHerat 发布时间: 2011-11-16
不是OR F姐!
作者: dawugui 发布时间: 2011-11-16

作者: AcHerat 发布时间: 2011-11-16
作者: abclm 发布时间: 2011-11-16
乌龟想说什么呢?
作者: dawugui 发布时间: 2011-11-16
if object_id('t3') is not null drop table t3 create table t3 (id int identity(1,1) primary key,name varchar(20)) go insert t3 select '18,15,20' union all select '18,20,20,15' union all select '18,20' union all select '15,20' union all select '20,18,20,15' union all select '20,15,20,18' go select * from t3 where name like '%15%' and name like '%18%' and (name like '%,15,%' or name like '15,%' or name like '%,15') and (name like '%,18,%' or name like '18,%' or name like '%,18') /* (所影响的行数为 4 行) id name --- ----- 1 18,15,20 2 18,20,20,15 5 20,18,20,15 6 20,15,20,18 */ go drop table t3
作者: xiaolinyouni 发布时间: 2011-11-16
SQL code
if object_id('t3') is not null
drop table t3
create table t3
(id int identity(1,1) primary key,name varchar(20))
go
insert t3
select '18,15,20' union all
select '18,20,20,15' union all
sel……
改为
SQL code
select * from t3 where (name like '%,15,%' or name like '15,%' or name like '%,15') and (name like '%,18,%' or name like '18,%' or name like '%,18')
作者: xiaolinyouni 发布时间: 2011-11-16
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28