7 kyu

Loan Eligibility: part 1

Description:

We have two tables: customers and loans.

customers table:

  • id (integer): The primary key for the table.
  • age (integer): The age of the customer.

loans table:

  • id (integer): The primary key for the table.
  • customer_id (integer): A foreign key referencing id in the customers table.
  • loan_status (string): The status of the loan, either 'paid' or 'unpaid'.
  • loan_amount (float): The amount of the loan.

Write a SQL query that returns a list of all customers who have IDs between 1 and 10. For each customer, the query should return their ID (as customer_id) and their loan eligibility based on the following criteria:

  • If the customer is 18 to 65 years old (inclusive) and all their loans are paid or they don't have any loans, they should be considered eligible for a loan, and the query should return 'loan can be given'.
  • Otherwise, the query should return 'loan cannot be given'.

The results should be sorted by customer_id in descending order.

GLHF!

Desired Output

The desired output should look like this:

customer_idloan_eligibility
10loan can be given
9loan can be given
8loan cannot be given
...
SQL
Databases

Similar Kata:

Stats:

CreatedJun 27, 2023
PublishedJun 28, 2023
Warriors Trained640
Total Skips69
Total Code Submissions2070
Total Times Completed302
SQL Completions302
Total Stars13
% of votes with a positive feedback rating88% of 43
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes3
Total Rank Assessments6
Average Assessed Rank
7 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad