[英]Combine multiple rows with same value into one row in oracle
I have been trying to solve an Oracle SQL query but to no avail and was hoping i could get some assistance. 我一直在尝试解决Oracle SQL查询,但无济于事,希望能得到一些帮助。 The scenario is that am querying the database and i get multiple records with the same value and wanted to combine the multiple rows into one.What i want to achieve is have the record for customer with IDNO =22099575 in one row instead of three as it appears in the attached screen shot of my result from my query below 场景是查询数据库,我得到了多个具有相同值的记录,并希望将多行合并为一个。我想要实现的是将IDNO = 22099575的客户记录放在一行中,而不是三行中出现在以下查询的附件屏幕快照中
SELECT concat(cu.firstname,cu.secondname)
Customername,cu.customerno,l.idnumber Idno,l.branch_code
Branchcode,l.phonenumber
Phone,cu.gender,l.grade,l.arocode,l.loanaccount,l.duedate,l.interest,
l.outstandingamount Outstandingloanbal,
l.lien Lienamount,TO_CHAR(l.applicationdate,'DD-MM-YY')
applicationdate,l.lastpaymentdate Lastcreditdate,l.inarrears
Principalloaninarrears,
l.rebate_amount Rebatepayable, l.empcode, l.disbursaldate, lt.description
Producttype,sum(l.amountdisbursed) Disbursedamt,
l.loanamount Principalamount,l.interest
Interestamount,l.flexi_refno,l.active
FROM ((ebank.tbloanaccount l
INNER JOIN ebank.tbcustomers cu ON l.customerno = cu.customerno)
INNER JOIN ebank.tbloantype lt ON l.productcode = lt.productcode)
where l.DISBURSED = '1'
group by concat(cu.firstname,cu.secondname), cu.customerno, l.idnumber,
l.branch_code, l.phonenumber,
cu.gender, l.grade, l.arocode, l.loanaccount,
l.duedate, l.interest, l.outstandingamount, l.lien,
TO_CHAR(l.applicationdate,'DD-MM-YY'),
l.lastpaymentdate, l.inarrears, l.rebate_amount, l.empcode, l.disbursaldate,
lt.description, l.loanamount, l.interest, l.flexi_refno, l.active order by
l.disbursaldate desc;
Here is a screen shot of my results from the above query: 这是上述查询的结果的屏幕截图:
you can use dense_rank on queries, to get latest due_date, outstanding loan. 您可以在查询中使用density_rank,以获取最新的到期日,未偿还的贷款。
SELECT concat(cu.firstname,cu.secondname)
Customername,cu.customerno,l.idnumber Idno,l.branch_code
Branchcode,l.phonenumber
Phone,cu.gender,l.grade,l.arocode,l.loanaccount, max(l.duedate) keep ( dense_rank first order by l.duedate desc ) duedate,l.interest,
max(l.outstandingamount) keep ( dense_rank first order by l.duedate desc ) Outstandingloanbal,
l.lien Lienamount,TO_CHAR(l.applicationdate,'DD-MM-YY')
applicationdate,l.lastpaymentdate Lastcreditdate,l.inarrears
Principalloaninarrears,
l.rebate_amount Rebatepayable, l.empcode, l.disbursaldate, lt.description
Producttype,sum(l.amountdisbursed) Disbursedamt,
l.loanamount Principalamount,l.interest
Interestamount,l.flexi_refno,l.active
FROM ((ebank.tbloanaccount l
INNER JOIN ebank.tbcustomers cu ON l.customerno = cu.customerno)
INNER JOIN ebank.tbloantype lt ON l.productcode = lt.productcode)
where l.DISBURSED = '1'
group by concat(cu.firstname,cu.secondname), cu.customerno, l.idnumber,
l.branch_code, l.phonenumber,
cu.gender, l.grade, l.arocode, l.loanaccount,
l.duedate, l.interest, l.outstandingamount, l.lien,
TO_CHAR(l.applicationdate,'DD-MM-YY'),
l.lastpaymentdate, l.inarrears, l.rebate_amount, l.empcode, l.disbursaldate,
lt.description, l.loanamount, l.interest, l.flexi_refno, l.active order by
l.disbursaldate desc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.