hana数据库 sql版本号字段的问题

例如有一张表 有如下几个字段 id ver money

id ver money
1 V1 111
1 V2 222
2 V1 666
3 V1 888
3 V2 999

根据id作为唯一标识,我想获取版本最大的数据 金额总和(222+666+999),请问下sql该怎么写,谢谢

已解决

先分组排序,然后再筛选出每组中的第一行,最后求和。另外,排序的确会有问题,当你版本大于10以后,按字符串排序就不对了,所以要转换成数字再来排序

select sum(b.money) from (
select a.*,row_number() over (partition by id order by CAST (replace(ver.'V','')  as INTEGER) desc) rn  from 表 a) as b
 where b.rn=1

分区取top1, 老实用row_number(〜 ̄▽ ̄)〜
select sum(money) from (
select *, over(partition by id order by ver desc) rn from table ) tmp where rn =1