答案 0 :(得分:3)
假设no
和yes
是字符串,您只需使用聚合:
select box, min(match) as match
from t
group by box;
这是因为值的字母顺序。更通用的解决方案是:
select box,
(case when sum(case when match = 'no' then 1 else 0 end) > 0
then 'no' else 'yes'
end) as match
from t
group by box;
答案 1 :(得分:0)
戈登的回答是我最有可能使用的,但你可以这样做....
spark.submit.deployMode=cluster
结果集:
declare @example as table (
exampleID int identity(1,1) not null primary key clustered
, box varchar(255) not null
, match varchar(25) not null
);
insert into @example (box, match)
select 'Box100', 'yes' union all
select 'Box100', 'yes' union all
select 'Box100', 'yes' union all
select 'Box200', 'yes' union all
select 'Box200', 'no' union all
select 'Box200', 'yes' union all
select 'Box300', 'yes' union all
select 'Box300', 'yes' union all
select 'Box300', 'yes' union all
select 'Box400', 'no' union all
select 'Box400', 'no' union all
select 'Box400', 'yes';
select distinct a.box
, isnull(b.match, c.match) match
from @example a
left join @example b
on a.box = b.box
and b.match = 'no'
left join @example c
on a.box = c.box
and c.match = 'yes'