首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从多值列查询不同的值。

从多值列查询不同的值。
EN

Stack Overflow用户
提问于 2014-03-17 03:10:04
回答 1查看 214关注 0票数 1

我试图查询“标记”列中的所有唯一值。标记列中的每一行可以由多个值组成。因此,在不被迫进行规范化的情况下,我如何查询多值列?

示例行:

代码语言:javascript
复制
Networking
Professionalism
Time Management
Communication, Networking
Career Management, Professionalism
Networking
Communication
Attitude, Interpersonal Skills, Professionalism
Business Protocol, Career Management, Communication, Leadership
Business Protocol, Networking
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-17 03:36:17

如果最大数量的元素是可预测的,您可以使用它(请注意,您需要使用UNION,而不是UNION ALL)

代码语言:javascript
复制
Select DISTINCT thefield from thetable where Instr(thefield, ',') = 0
UNION 
Select Distinct Mid(thefield, 1, Instr(thefield, ',')) from thetable Where len(thefield) - len(replace(thefield,',','')) = 1
UNION 
Select Distinct Mid(thefield, Instr(thefield, ',')+1) from thetable Where len(thefield) - len(replace(thefield,',','')) = 1
UNION 
Select Distinct Mid(thefield, Instr(thefield, ',')+1, Instr(Instr(thefield, ',')+1,thefield, ',')) from thetable Where len(thefield) - len(replace(thefield,',','')) = 2
UNION 
Select Distinct Mid(thefield, Instr(Instr(thefield, ',')+1,thefield, ',')+1) from thetable Where len(thefield) - len(replace(thefield,',','')) = 2
--.. and so on (repeat last two Selects as many time as you wish, increasing the where condition by one for each pair)

看上去有点笨重,但应该做好这项工作。未经测试,因此,您可能会在值之前或之后出现一个偏离逗号。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22446293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档