Вопрос

I'm only looking at one table, I have the values I need to match, so.

Col A / Col B
1 / 1
1 / 2
1 / 3
2 / 2
2 / 3
4 / 1
4 / 3

So the values I pass in would be 1 and 3 and I'd want to return 1 and 4.

I've tried a group by with a could, where I've had to use two sub queries, but it didn't work.

EDIT: Ideally I'd like to use a select query as I need to use this query within another query which I'm building up outside of sql server.

EDIT2: Ideally I'd like to pass in my input as a csv string

Это было полезно?

Решение

select ColA 
from your_table
where ColB in(1, 3)
group by ColA
having count(ColA) > 1

Другие советы

If I've understood correctly the values passed in relate to ColumnB and the return values come from ColumnA:

SELECT      A.ColumnA
FROM        [YOUR TABLE] A
INNER JOIN  [YOUR TABLE] ON ( A.ColumnA = B.ColumnA AND B.ColumnB = 1 )
WHERE       A.ColumnB = 3
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top