partition by相比較於group by,可以在保留所有數據的基礎上,只對其中某些字段作分組排序(相似excel中的操做),excel
row_number() over()分組排序功能排序
select * from(
select * ,row_number() over(partition by propertyNo order by case when agentType='SHARE' then 1 when agentType='BROWSE' then 2
when agentType='INVITE' then 3 when agentType='VISIT' then 4 when agentType='SURVEY' then 5
when agentType='FOLLOW' then 6 end) rn from T_AgentTohouse ) tn where tn.rn=1it