请考虑此表:
firstName | lastName | hobby
-----------------------------
Mike | Stone | music
Sarah | James | cooking
Mike | Stone | jogging
Greg | Jones | reading
Sarah | James | music
Mike | Stone | painting
-----------------------------
如何为每个不同的firstName,lastName组合选择一个爱好(无关紧要)? (在Oracle中)
所需结果的一个例子是:
firstName | lastName | hobby
-----------------------------
Mike | Stone | music
Sarah | James | cooking
Greg | Jones | reading
-----------------------------
感谢您的帮助..
萨姆
答案 0 :(得分:5)
您可以执行类似
的操作select firstname, lastname, max(hobby) as hobby
from names
group by firstname, lastname
您可以使用max的其他功能为您提供不同的答案,例如,min。