首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Server选择

Server选择
EN

Stack Overflow用户
提问于 2016-06-09 19:39:25
回答 4查看 95关注 0票数 2

我有下表,名为tblMastTestElement

代码语言:javascript
复制
cTestCode    |  cElementCode
24HCRECLE    |  CRE
CALCRECLE    |  CRE
CALEXR       |  CRE
CRE          |  CRE
CRECLE       |  CRE
EGFR         |  CRE
EGFR         |  EG          

我需要一个查询来返回EGFR作为测试代码,其中只有元素CRE和EG。

像这样的东西

代码语言:javascript
复制
Select cTestCode
from tblMastTestElement
where cElementCode IN('CRE' And 'EG')
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-06-09 19:49:21

要返回具有cElementCode for cElementCode,可以使用 'CRE‘和'EG’(而不是)。

代码语言:javascript
复制
SELECT cTestCode
FROM   tblMastTestElement
WHERE  cElementCode IN ( 'CRE', 'EG' )
GROUP  BY cTestCode
HAVING COUNT(DISTINCT cElementCode) = 2 
票数 4
EN

Stack Overflow用户

发布于 2016-06-09 19:51:53

代码语言:javascript
复制
Select distinct t1.cTestCode
from tblMastTestElement t1
join tblMastTestElement t2 on t2.cTestCode = t1.cTestCode
where t1.cElementCode = 'EG'
and t2.cElementCode = 'CRE'
票数 2
EN

Stack Overflow用户

发布于 2016-06-09 19:51:17

这样就行了。

代码语言:javascript
复制
Select t1.cTestCode
from tblMastTestElement t1
where t1.cElementCode = 'CRE'
AND EXISTS (
    Select 1
    from tblMastTestElement t2
    where t2.cElementCode = 'EG'
    AND t1.cTestCode = t2.cTestCode)
)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37734809

复制
相关文章

相似问题

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