0

I have a table as

COl1____COL2____COL3
1_________1_____val1
1_________2_____val2
1_________3_____val3

2_________1_____val1
2_________2_____val2
2_________3_____val3

3_________1_____val1
3_________2_____val2
3_________4_____val4

No I want to have unique values from COL1 such that it should only show me COL1 value that does not have a value "3" under COL2

i.e. I want a query to return me

Result
3

Any help is much appreciated

4

2 回答 2

3
SELECT col1
FROM   YourTable
EXCEPT
SELECT col1
FROM   YourTable
WHERE  col2 = 3 

或者

SELECT col1
FROM   YourTable
GROUP  BY col1
HAVING MAX(CASE
             WHEN Col2 = 3 THEN 1
             ELSE 0
           END) = 0
于 2013-07-01T10:06:27.703 回答
1
select col1
from Tab
where col1 not in (select col1 from tab where col2 = 3)
于 2013-07-01T10:06:06.637 回答