当前位置: 代码迷 >> Oracle管理 >> 求分组后,在追加的sql
  详细解决方案

求分组后,在追加的sql

热度:20   发布时间:2016-04-24 04:37:20.0
求分组后,在累加的sql

create table INVEST_INFO
(
  invest_id         NUMBER not null,
  loan_id           NUMBER not null,
  user_id           NUMBER not null,
  invest_amount     NUMBER(22,7) not null,
  hava_scale        NUMBER(22,18) not null,
  invest_time       TIMESTAMP(0) not null,
  description       VARCHAR2(200),
  status            VARCHAR2(2),
  ledger_finance_id NUMBER,
  funds_source      NUMBER
)
根据user_id和status查询,如果结果里loan_id相同,把invest_amount累加
显示查询后的记录

------解决方案--------------------
这样?
select user_id,status,loan_id,sum(invest_amount)
from INVEST_INFO
group by user_id,status,loan_id

------解决方案--------------------
select loan_id,sum(invest_amount)
from INVEST_INFO
where user_id=?
and status=?
group by loan_id
  相关解决方案