取最大值的记录

如何取表中某个字段的最大值的记录,当然有很多办法,可是一直想一个简单sql搞定,今年看着例子想了好久才蹩过这个弯儿来,趁没忘记录一下——其实是例子没看仔细,这个悄悄说,不要让别人听到 :oops:
取某人在去年的最高 月均资产(avg_asset) 记录

select
account_id,
month_id,
end_balance_rmb+end_balance_usd+end_balance_hk,
end_stockvalue_rmb+end_balance_hk+end_balance_usd,
end_asset,
end_balance_rmb+end_balance_usd+end_balance_hk+end_gj_stockvalue,
(end_asset+end_unbond_balance)-(begin_asset+begin_unbond_balance)-(total_in_deposit+total_out_deposit+total_in_stockvalue+total_out_stockvalue),
(total_out_deposit+total_in_deposit),
total_in_stockvalue+total_out_stockvalue,
total_commis,
case when gj_match_balance=0 then 0 else
gj_commis/gj_match_balance end,
total_interest,
total_commis+total_interest,
total_match_balance,
case when total_match_balance=0 then 0 else
nolocal_match_balance / total_match_balance end,
case when total_match_balance=0 then 0 else
web_match_balance / total_match_balance end,
case when avg_asset = 0 then 0 else
total_match_balance / avg_asset end,
end_of_stockvalue
from
(
select max(t.AVG_ASSET) over (partition by t.account_id) asset, t.*
from olap.vw_fact_account_by_month t
where t.account_id=i_account_id and t.month_id >= 200801 and t.month_id <= 200812
) e
where e.asset=e.AVG_ASSET;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值