全外部自我加入或其他

时间:2017-12-21 07:04:18

标签: sql sql-server

MID RID Name IsVisible
100 1   AA      1
100 2   AA      0
101 1   BB      1
101 2   BB      1
102 1   CC      0
102 2   CC      0 
103 1   DD      0
103 2   DD      1

如何在所有RID中选择IsVisible = 0的不同MID。

预期结果为102,对于所有RID,IsVisible = 0。

2 个答案:

答案 0 :(得分:0)

使用class Trie: def __init__(self): self.word_end = '_end_' self.root = {} def add_word(self, word): self.add_words([word]) def add_words(self, words): for word in words: current_dict = self.root for letter in word: current_dict = current_dict.setdefault(letter, {}) current_dict[self.word_end] = self.word_end def check_word(self, word): current_dict = self.root for letter in word: if letter in current_dict: current_dict = current_dict[letter] else: return False else: if self.word_end in current_dict: return True else: return False tree = Trie() tree.add_words(['foo', 'bar', 'baz', 'barz']) print tree """ {'b': {'a': {'r': {'_end_': '_end_', 'z': {'_end_': '_end_'}}, 'z': {'_end_': '_end_'}}}, 'f': {'o': {'o': {'_end_': '_end_'}}}} """ print check_word('baz') # True print check_word('barz') # True print check_worf('barzz') # False

NOT EXISTS

答案 1 :(得分:0)

这个问题有点不清楚,但也许这就是你想要的......?

执行GROUP BY,检查max和min IsVisible = 0。

select MID
from tablename
group by MID
having max(cast(IsVisible as int)) = 0