用row_number()select col1,col2,col3,col4 from ( select col1,col2,col3,col4,row_number()over(partition by col1,col2,col3 order by col4 desc) rm from table ) where rm=1;
那你应该是想要最后一次发送时间的记录吧? select 手机号码, 短信内容, 发送失败标志, 发送时间 from (select 手机号码, 短信内容, 发送失败标志, 发送时间, row_number() over(partition by 手机号码 order by 发送时间 desc) rn from 表) where rn = 1
try it ..SELECT 手机号码,短信内容,发送失败标志, MAX(发送时间) FROM MOBILES_HISTORY GROUP BY 手机号码,短信内容,发送失败标志;
select 手机号码, 短信内容, 发送失败标志, 发送时间 from table where (手机号码, 短信内容, 发送失败标志, 发送时间)not in (select 手机号码, 短信内容, 发送失败标志, max(发送时间) from table group by 手机号码, 短信内容, 发送失败标志)
谢谢,能解释一下“row_number() over(partition by 手机号码 order by 发送时间 desc) rn”的意思吗?
select col1,col2,col3,col4,row_number()over(partition by col1,col2,col3 order by col4 desc) rm from table
) where rm=1;
select 手机号码, 短信内容, 发送失败标志, 发送时间
from (select 手机号码,
短信内容,
发送失败标志,
发送时间,
row_number() over(partition by 手机号码 order by 发送时间 desc) rn
from 表)
where rn = 1
MAX(发送时间)
FROM MOBILES_HISTORY
GROUP BY 手机号码,短信内容,发送失败标志;
from table
where (手机号码, 短信内容, 发送失败标志, 发送时间)not in (select 手机号码, 短信内容, 发送失败标志, max(发送时间)
from table group by 手机号码, 短信内容, 发送失败标志)
效率不高。