数据库
首页 > 数据库> > mysql面试题3

mysql面试题3

作者:互联网

表1:货款基本信息表
LOAN_NO ID_NO ACTV_DT
1000114260 1 2011-06-07
1000143723 2 2011-09-21
1000162024 3 2011-12-09
1000174934 4 2012-03-23
1000182256 5 2012-05-15
LOAN_NO:贷款编号
ID_NO:贷款人身份编号
ACTV_DT:放款日期

表2:贷款逾期天数表
LOAN_NO OD_DAYS
1000114260 90
1000174934 16
1000182256 0
1000143723 45
1000162024 3
LOAN_NO:贷款编号
OD_DAYS:贷款逾期天数

表3:贷款人信用记录表
ID_NO LIM OUTSTANDING
5 30000 25110
2 40000 40000
2 50000 56000
2 45000 45000
1 15000 6378
1 80000 60395
3 60000 57773
4 30000 28656
4 30000 10000
ID_NO:贷款人身份编号
LIM:贷款人在我司带框之前在其他
OUTSTANDING:贷款人在我司贷款之前在其他小额贷款公司贷款金额

表4
LOAN_NO ID_NO ACTV_DT OD_DAYS TYPE LIM OUTSTANDING
1000114260 1 2011-06-07 90 CHRGO 95000 66773
1000143723 2 2011-09-21 45 MIDDLE 135000 141000
1000162024 3 2011-12-09 3 MIDDLE 60000 57773
1000174934 4 2012-03-23 18 MIDDLE 60000 38656
1000182256 5 2012-05-15 0 CURRENT 30000 25110
TYPE:根据贷款逾期天数定义贷款类型(如果贷款逾期天数等于0则贷款类型为CURRENT;如果贷款逾期天数大于0且小于等于89则带框类型为MIDDLE;如果贷款逾期天数大于等于90则贷款类型为CHRGO)

要求:利用表1、表2、表3经过处理得到表4。

CREATE DATABASE DB1;
USE DB1;

create table a1(LOAN_NO INT,
ID_NO INT,
ACTV_DT DATE);

create table a2(LOAN_NO INT,
OD_DAYS INT);

create table a3(ID_NO INT,
LIM INT,
OUTSTANDING INT);

insert into a1 values(1000114260,1,‘2011-06-07’),
(1000143723,2,‘2011-09-21’),
(1000162024,3,‘2011-12-09’),
(1000174934,4,‘2012-03-23’),
(1000182256,5,‘2012-05-15’);

insert into a2 values(1000114260,90),
(1000174934,16),
(1000182256,0),
(1000143723,45),
(1000162024,3);

insert into a3 values( 5,30000,25110),
(2,40000,40000),
(2,60000,56000),
(2,45000,45000),
(1,15000,6378),
(1,80000,60395),
(3,60000,57773),
(4,30000,28656),
(4,30000,10000);

select a1.LOAN_NO,a1.ID_NO,ACTV_DT,OD_DAYS,
IF(OD_DAYS=0,‘CURRENT’,IF(OD_DAYS>=90,‘CHRGO’,‘MIDDLE’)) AS TYPE,
SUM(LIM),OUTSTANDING FROM a1 left join a2 on a1.LOAN_NO = a2.LOAN_NO
left join a3 on a1.ID_NO = a3.ID_NO
GROUP BY a1.LOAN_NO;

标签:面试题,NO,LOAN,OD,a1,mysql,2011,ID
来源: https://blog.csdn.net/cxlgood/article/details/116584679