我需要一个查询来获取一个列n中具有重复值而另一个列中具有不同值的行。例如,如果我有:
definition
bat job .... .....
Hi apple
Hi babana
Bye apple
Bye apple
我需要获得:
bat job job
Hi apple babana
我尝试使用这些查询,但不起作用:-(
select a.bat, a.job, b.job from definition a inner join definition b on
( a.bat=b.bat and
a.job <> b.job
and a.bat in (select bat from definition group by bat having count(*)>1));
请帮忙吗?感谢
如果我理解正确,您可以使用聚合:
select bat, min(job), max(job)
from t
group by bat
having min(job) <> max(job);