문제

I am trying to find whether a set of numbers are contained in another set of numbers.

ID NumberSet Result  
-- --------- ------
1  1457      5741
2  4187      7148
3  6324      1345

So for this dataset I would return ID 1 & 2. All the numbers from the NumberSet must be contained within the Result.

Any suggestions?

도움이 되었습니까?

해결책

This actually isn't that hard. Just look for the reverse . . . is there a case where a number from NumberSet is not in Result?

For the first row, you could manually create a like expression for finding a result that has a character other than "1457":

where Result like '%[^1457]%'

What you want is:

where Result not like '%[^1457]%'

Now, let's generalize:

where Result not like '%[^'+NumberSet+']%'

다른 팁

It seems not easy but you can look into this blog http://wikiprogrammer.wordpress.com/2011/10/17/find-out-anagram-using-sql/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top