繁体   English   中英

选择具有所有逗号分隔字符串的数据

[英]Select Data which have all comma separated strings

我有一个条件表

id   condition   member-id
 1    Fall         A1452
 2    Fall         A1453
 3    Dementia     A1452
 4    Dementia     A1453
 5    Fall         A1450
 6    Headaches    A1453

现在,我想要通过条件作为参数,例如“ Fall,Dementia”,我希望同时具有FallDementia条件的那些会员ID

select * from conditions where condition IN('Fall,Dementia')

这将返回3条记录,但我需要同时拥有这两项的记录?

请记住,“秋季,痴呆症”是动态的,可能会更改为“秋季,痴呆症,头痛”

使用条件聚合

 select MemberId from 
 conditions
 where condition IN('Fall','Dementia')
 group by MemberId
 having count(distinct condition )=2 
 select distinct MemberId 
 from StackOverflow4
 where Condition in ('Fall','Dementia')
 group by memberId
 having count(MemberId)=2 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM