Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SQL QUESTIONS

Table name: members


Description: Member ID and information. Contains information for both investor and borrower, which is flagged in the
member_type column
MEMBER_ID COUNTRY_CODE COMPANY_NAME FULL_NAME CITIZENSHIP_COUNTRY MEMBER_TYPE
52 SG NULL Jamie Yeo SG investor
51 SG NULL Desmond Chua SG investor
23 ID NULL Peter Ong US investor
24 ID NULL Derrick Low MY investor
63 MY NULL Fany Wong MY investor
21 SG Good books pte ltd NULL NULL borrower
74 SG Apple inc NULL NULL borrower
93 SG Fruit pte ltd NULL NULL borrower
... ... ... ... ...

Primary_key = member_id

Table name: loans


Description: Shows the loans and corresponding borrower (member_id) who took the loan. Each loan can only have 1 borrower
LOAN_ID MEMBER_ID
9391 21
9493 93
837 17
5235 42
123 21
... ...
primary_key = loan_id
foreign_key = member_id >> members.member_id

Table name: investments


Description: Shows loan details along with the investors that invested in the loan. Summing the amount will give you the total
amount raised for each loan.
LOAN_ID MEMBER_ID AMOUNT (USD) INVESTMENT_DATE

9391 52 500 2018-03-21 06:22:05.317


9391 51 10000 2018-03-26 07:59:15.431
9391 24 300 2017-08-02 23:59:48.000
837 23 200 2017-06-21 06:02:15.000
837 51 50 2017-09-18 07:27:28.000
5235 52 400 2017-08-29 15:04:54.000
5235 63 300 2017-10-05 09:40:57.000
5235 51 300 2018-03-08 08:07:42.155
... ... ... ...
foreign_key = member_id >> members.member_id
foreign_key = loan_id >> loans.loan_id
1. Write SQL queries for the following. Comment on your rationale if necessary.
a. For each available loan_id, get the corresponding company name.
b. Find out how many borrowers we have per country
c. Find out how many investors per CITIZENSHIP_COUNTRY invested in loan 9493
d. Find out the total amount invested and number of investors who participated in at least 1 loan in each
month per year, for loans originating in SG (i.e. loans by SG borrowers)
e. Find out which loan(s) raised more than USD10,000 in 2017.
f. Find the top 10 largest loans in terms of amount raised in 2017 per country. Do not use UNION as we do
not want to query the table multiple times.

2. We have two tables (see below). One table has all mobile actions, i.e. all pages visited by the users on
mobile. The other table has all web actions, i.e. all pages visited on web by the users.

Write a query that returns the percentage of users who only visited mobile, only web and both. That is, the
percentage of users who are only in the mobile table, only in the web table and in both tables. The sum of the
percentages should return 1.

Table name: mobile

USER_ID DATE PAGE

13399 1/3/15 page_5_mobile

11934 1/3/15 page_10_mobile

3542 1/3/15 page_2_mobile


Table name: web

USER_ID DATE PAGE

123 1/3/15 page_4_web

11934 1/3/15 page_11_web

3542 1/3/15 page_8_web

...

You might also like