日期:2014-05-17  浏览次数:20807 次

求分组后,在累加的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