MySQL Forums
Forum List  »  Newbie

Need help with my sql
Posted by: Arnoldas Jasulis
Date: February 11, 2017 04:26PM

So i have 2 tables
first one credit_applications
Customer id Credit application date Credit application amount Credit Application Status Credit application approve date
111232 2017.01.03 5000 Open
111323 2017.01.03 10000 Approved 2017.01.10
111323 2017.01.04 8000 Approved 2017.01.10
111323 2017.01.05 110000 Terminated
105988 2016.10.15 20000 Approved 2016.11.11
111124 2017.01.03 6000 Terminated
111125 2017.01.06 130000 Open
111125 2017.01.07 5000 APPROVED 2017.01.11
100000 2017.01.11 15500 Open
100000 2017.01.12 10000 APPROVED 2017.01.12
121212 2017.01.02 5000 Terminated
111122 2017.01.06 26000 Approved 2017.01.12
125254 2016.12.12 8900 Open
136256 2016.12.26 15000 Approved

2nd Customer

Customer id Age Country Risk group
111232 25 DK A1
111323 30 DK A2
105988 56 LT A2
111124 28 DK A1
111125 33 DK B1
100000 55 DK A2
121212 20 LT A2
111122 38 DK B1
125254 46 DK B1
136256 20 DK A2

And i have these assigments
-customer id
-customer age
-customer risk group
-number of credit applications, which where created on 2017
-date of last approved credit application
-amount of last approved credit application

SQL query should order customers by id and risk group.



I wrote the query :

SELECT credit_applications.customer_id, age, risk_group, sum(date(credit_application_date) > '2017-01-01') as 'credit application created in 2017', max(credit_application_approve_date) as 'last_approved_date', sum(case when credit_application_approve_date!='0'and credit_application_status ='Approved' or 'APPROVED' then credit_application_amount else NULL end) as 'latest approved ammount'
FROM credit_applications left join customers on credit_applications.customer_id = customers.customer_id
group by customer_id
order by customer_id,risk_group


Ant i stuck at 6th assigment, i dont know how to get lastet credit application approve date becouse i cant use max in canse sentince, Please help me :)

Options: ReplyQuote


Subject
Written By
Posted
Need help with my sql
February 11, 2017 04:26PM
February 11, 2017 06:19PM
February 12, 2017 01:28AM
February 12, 2017 01:41AM
February 12, 2017 02:29AM
February 12, 2017 01:05PM
February 12, 2017 03:09PM
February 12, 2017 04:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.