select id,
(case when min(color) is not distinct from max(color) and
min(size) is not distinct from max(size) and
min(shape) is not distinct from max(shape) and
min(area) is not distinct from max(area)
then 'same'
else 'mixed'
end)
from table
where id in (1, 2, 3)
group by id;
또한 당이 작업을 수행 할 수 있습니다 열뿐만 아니라.
편집 :
내가 먼저 대답부터 문제가 조금 변경되었습니다 (또는 적어도 내가 오해) 생각 :
select (case when min(color) = max(color) and count(*) = count(color) or
min(color) is null
then min(color) else 'mixed'
end) as color,
(case when min(size) = max(size) and count(*) = count(size) or
min(size) is null
then min(size) else 'mixed'
end) as size,
(case when min(color) = max(shape) and count(*) = count(shape) or
min(shape) is null
then min(shape) else 'mixed'
end) as shape,
(case when min(area) = max(area) and count(*) = count(area) or
min(area) is null
then min(area) else 'mixed'
end) as area
from table
where id in (1, 2, 3);
결과로 네 개의 열이있는 단일 행을 원하십니까? –