我有数据,其中group将一行作为零和一,对于相同的数据值将给出一和两。
我尝试使用下面的代码。它似乎不起作用
select *
from (select livecasnum, flag,
DENSE_RANK()over (partition by livecasnum order by flag) as Ranks
from TblcaseFlag
group by livecasnum, flag
) b
group by livecasnum,flag,Ranks
having count(flag + Ranks) = 1 and flag <> 1
我只需要一排只有零和一个ex的数据:99149
答案 0 :(得分:1)
为什么不使用not exists
呢?
select tf.*
from TblcaseFlag tf
where tf.flag = 0 and
not exists (select 1
from TblcaseFlag tf1
where tf.livecasnum = tf1.livecasnum and
tf1.flag = 1
);