我的查询:
SELECT sites.siteName,sites.siteIP,history.date FROM sites INNER JOIN history ON sites.siteName = history.siteName ORDER BY siteName,date
第一部分输出:
如何删除siteName列中的重复项?我只想根据日期栏留下更新的.
在上面的示例输出中,我需要行1,3,6,10
解决方法
这是窗口函数row_number()派上用场的地方:
SELECT s.siteName,s.siteIP,h.date FROM sites s INNER JOIN (select h.*,row_number() over (partition by siteName order by date desc) as seqnum from history h ) h ON s.siteName = h.siteName and seqnum = 1 ORDER BY s.siteName,h.date