0

我有一个如下表T。

我想选择一个拥有其身份Processed, InProgress组合的客户。

请你帮忙,我该怎么做?

桌子

ClientId    ClientName  Status
1           A           Processed
1           A           Processed
2           b           InProgress
2           b           Processed
3           c           Processed
3           c           Processed
4           d           InProgress
4           d           Processed
5           e           InProgress
5           e           Processed  

结果应该是

ClientId    ClientName  Status
2           b           InProgress
2           b           Processed
4           d           InProgress
4           d           Processed
5           e           InProgress
5           e           Processed  

先感谢您

4

2 回答 2

1

你在找这个吗?

SELECT * FROM T 
WHERE 
    clientId IN 
    (
        SELECT T1.clientId 
        FROM 
            T t1 JOIN T t2 
            ON t1.clientId = t2.clientId 
        WHERE 
            (t1.status = 'Processed' AND t2.status = 'InProgress') OR 
            (t2.status = 'Processed' AND t1.status = 'InProgress')
    )
于 2012-09-20T18:11:02.247 回答
0

如果我理解正确,我会这样做以获得结果

select ClientId, ClientName, Status From Table T
where Status IN ('Processed', 'InProgress')
于 2012-09-20T18:14:28.017 回答