-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIUVO_PM_SM_VIEW.sql
82 lines (78 loc) · 1.49 KB
/
IUVO_PM_SM_VIEW.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
create view IUVO_ALL as
select
IUVO.Country,
IUVO.ID,
IUVO.IssueDate,
IUVO.LoanType,
IUVO.AmortizationMethod,
IUVO.LoanOriginator,
IUVO.ScoreClass,
IUVO.GarPRC,
IUVO.Currency,
IUVO.IR,
MIN(IUVO.Term) as Term,
MAX(IUVO.PaymentsReceived) as PaymentsReceived,
IUVO.InstalmentType,
SUM(IUVO.AvailableforInvestment) as AvailInv,
MAX(IUVO.MyInvestment) as MyInvestment,
IUVO.Date,
INST.Instalment,
MAX(STAT.Delay) as Delay
from
( select
Country,
ID,
IssueDate,
LoanType,
AmortizationMethod,
LoanOriginator,
ScoreClass,
`GuaranteedofPrincipal(%)` as GarPRC,
Currency,
`InterestRate(%)` as IR,
Term,
PaymentsReceived,
InstalmentType,
Status,
AvailableforInvestment,
MyInvestment,
Date
from
IUVO_PM
union
select distinct
Country,
ID,
IssueDate,
LoanType,
AmortizationMethod,
LoanOriginator,
ScoreClass,
`GuaranteedofPrincipal(%)` as GarPRC,
Currency,
`InterestRate(%)`as IR,
Term,
PaymentsReceived,
InstalmentType,
Status,
AvailableforInvestment,
MyInvestment,
Date
from
IUVO_SM) IUVO
LEFT JOIN IUVO_INSTALMENT AS INST ON IUVO.InstalmentType = INST.InstalmentType
LEFT JOIN IUVO_STATUS AS STAT ON IUVO.Status = STAT.Status
GROUP BY
IUVO.Country,
IUVO.ID,
IUVO.IssueDate,
IUVO.LoanType,
IUVO.AmortizationMethod,
IUVO.LoanOriginator,
IUVO.ScoreClass,
IUVO.GarPRC,
IUVO.Currency,
IUVO.IR,
IUVO.InstalmentType,
IUVO.Date,
INST.Instalment