答案 0 :(得分:1)
您可以使用print (df.groupby('A')['B'].agg(pd.Series.nunique))
:
print (df.groupby('A')['B'].apply(pd.Series.nunique))
A
1 1
2 1
Name: B, dtype: int64
如果您只想使用不同类型的exists
,那么聚合很方便:
select t.*
from t
where exists (select 1
from t t2
where t2.SrlNbr = t.SrlNbr and t2.type <> t.type
);
答案 1 :(得分:1)
对于您的问题,我有一个简单的解决方案,只需将表名放在您的表处即可。
请检查下面的查询。
SELECT a.ID
,a.SrlNbr
,a.Type
,a.[Desc]
FROM Your_Table AS a
INNER JOIN Your_Table AS b ON a.SrlNbr = b.SrlNbr
WHERE a.Type != b.Type