Data Analytics, Data Science, and Data Engineering employees at American Equity uses SQL for analyzing customer data trends, such as tracking policyholder demographics and behavior. It is also used for managing financial asset data, including optimizing investment portfolios and reducing financial risk, which is why American Equity asks prospective hires SQL coding interview questions.
So, to help you study, we've collected 9 American Equity Investment Life Holding SQL interview questions – can you solve them?
American Equity is a financial services company that gives out home mortgages, and part of your job is to identify the "whale" customers, i.e. those that take large loans frequently.
Given a table with the following schema:
loan_id | user_id | loan_date | loan_amount |
---|---|---|---|
1359 | 567 | 03/08/2019 | 450000 |
2467 | 347 | 03/05/2021 | 500000 |
2589 | 437 | 03/20/2021 | 600000 |
3475 | 567 | 04/12/2021 | 500000 |
4578 | 978 | 07/15/2021 | 400000 |
Write a SQL query that would return the , and total loan amount and count of loans for each user, sorted by total loan amount in descending order, for users that have borrowed more than $1 million in total over at least 2 different instances.
Your result should look like this:
user_id | total_loan_amount | loan_count |
---|---|---|
567 | 950000 | 2 |
347 | 500000 | 1 |
Here is a PostgreSQL query that would solve this:
This query groups the loans by , then sums and counts how many loans each user has taken. The clause excludes users that have taken loans adding up to less than $1 million or have less than two loans. Finally, the results are ordered by in descending order to prioritize the biggest borrowers.
To practice a related customer analytics question on DataLemur's free interactive SQL code editor, try this Microsoft Azure Cloud SQL Interview Question:
You're given a table of American Equity employee and department salary information. Write a SQL query to find departments where the departments average salary is higher than the company's average salary.
Solve this question directly within the browser on DataLemur:
The answer is LONG – 30+ lines of SQL. You can find a step-by-step solution here: Department vs. Company Salary.
If you want to return records with no duplicates, you can use the keyword in your statement.
For example, if you had a table of American Equity employees, and wanted to see what are all the unique job titles that currently worked at the company, you could write the following query:
If had the following data:
f_name | job_title |
---|---|
Akash | Data Analyst |
Brittany | Data Scientist |
Carlos | Data Engineer |
Diego | Data Engineer |
Eva | Data Analyst |
Then the output from the query would be:
job_title |
---|
Data Analyst |
Data Scientist |
Data Engineer |
American Equity sells annuity policies. Each policy has a , , , and . We would like to know for every what is the total amount of policies they purchased over each year and rank their annual total purchase from highest to the lowest.
For example, if John Doe purchased 2000 in June 2021, 3000, and $3000 in 2022. And the rank for 2021 would be 2 and for 2022 would be 1.
purchase_date | policy_number | client_id | purchase_amount |
---|---|---|---|
01/01/2021 | 4651 | 108 | 1000 |
06/01/2021 | 6543 | 108 | 2000 |
01/01/2022 | 5643 | 108 | 3000 |
07/01/2021 | 9865 | 205 | 5000 |
08/01/2022 | 8765 | 205 | 2000 |
client_id | year | total_purchase | purchase_rank |
---|---|---|---|
108 | 2021 | 3000 | 2 |
108 | 2022 | 3000 | 1 |
205 | 2021 | 5000 | 2 |
205 | 2022 | 2000 | 1 |
This query first groups rows by and year of , and sums up for each group. Then it uses window function to rank these sums within each . The ranking order is descending by the total purchase amount, meaning that the higher the total purchase, the higher the rank. The clause at the end is to sort the result by and .
p.s. Window functions show up super frequently during SQL interviews, so practice the 27+ window function questions on DataLemur
A database index is a data structure that improves the speed of data retrieval operations on a database table.
There are few different types of indexes that can be used in a database:
For a concrete example, say you had a table of American Equity customer payments with the following columns:
Here's what a clustered index on the column would look like:
A clustered index on the column would determine the physical order of the records in the table based on the . This means that the records with the earliest values would be stored together physically in the table, followed by records with later payment_date values. This speeds up queries that filter or sort the data based on the , as the records are already physically sorted in the table. For example, if you want to retrieve all the payments made in the month of June, the database can use the clustered index to quickly locate and retrieve the desired records without having to search through the entire table.
American Equity is a company that offers annuities and life insurance products. We'll simulate a situation where they want to analyze the performance of their financial products (annuities) based on the average returns and the amount of investment made in each product. They have two tables, named and .
The table includes information about each product such as , and .
The table contains investment transactions providing , , , and .
You need to write an SQL query that would help American Equity to find the average per product, listing the and the in the final output.
product_id | product_name | product_type |
---|---|---|
1 | Fixed Annuity | Annuity |
2 | Indexed Annuity | Annuity |
3 | Survivorship Life | Life Insurance |
4 | Indexed Survivorship Life | Life Insurance |
investment_id | product_id | investor_id | investment_date | investment_amount |
---|---|---|---|---|
101 | 1 | 5010 | 2020-09-23 | 5000 |
102 | 2 | 5011 | 2020-12-11 | 7000 |
103 | 1 | 5010 | 2021-01-20 | 6000 |
104 | 2 | 5012 | 2021-04-02 | 8000 |
105 | 1 | 5011 | 2021-07-14 | 5500 |
SQL code:
This query first joins table and table on . Then it groups the result by and evaluates the average for each group, i.e., for each . The final output will contain and their respective .
A full outer join returns all rows from both tables, including any unmatched rows, whereas an inner join only returns rows that match the join condition between the two tables.
For an example of each one, say you had sales data exported from American Equity's Salesforce CRM stored in a datawarehouse which had two tables: and .
: retrieves rows from both tables where there is a match in the shared key or keys.
This query will return rows from the sales and tables that have matching customer id values. Only rows with matching values will be included in the results.
: retrieves all rows from both tables, regardless of whether there is a match in the shared key or keys. If there is no match, NULL values will be returned for the columns of the non-matching table.
Here is an example of a SQL full outer join using the sales and tables:
American Equity is an insurance company that sells various types of policies to its customers. Each policy has a regular premium paid by the customer. For the data analysis department, write a SQL query to calculate the average monthly premium received from customers for each type of insurance policy sold by the company.
Here is your sample data:
policy_id | customer_id | start_date | insurance_type | premium |
---|---|---|---|---|
1001 | 867 | 01/03/2022 | Home | 1100 |
1002 | 302 | 02/12/2022 | Car | 900 |
1003 | 867 | 03/08/2022 | Life | 1200 |
1004 | 44 | 02/29/2022 | Car | 950 |
1005 | 44 | 04/16/2022 | Health | 800 |
month_year | insurance_type | avg_monthly_premium |
---|---|---|
2022-01 | Home | 1100.00 |
2022-02 | Car | 925.00 |
2022-03 | Life | 1200.00 |
2022-04 | Health | 800.00 |
Here is a SQL query that meets the requirements, written for PostgreSQL:
This query groups the insurance premiums by the month of policy start date and insurance type to yield the average premium per month. This will help the data analysis team to track the average monthly revenue from each type of insurance policy. The use of function extracts the year and the month from the date column, and calculates the average premium.
As a database administrator for the company American Equity, your task is to retrieve the customer records for those customers who have similiar names. The marketing department decided to create personalized marketing strategies based on these groups and parts of the name can be used as a grouping basis. They ask you to find all customer records where the customer's name begins with 'Rob'.
Here is an example customer records data:
customer_id | first_name | last_name | signup_date | |
---|---|---|---|---|
301 | Robert | Smith | robertsmith@example.com | 01/22/2021 |
302 | Robin | Johnson | robinjohnson@example.com | 03/10/2021 |
303 | James | Martin | jamesmartin@example.com | 04/17/2021 |
304 | Roberto | Garcia | robertogarcia@example.com | 06/27/2021 |
305 | Jennifer | Brown | jenniferbrown@example.com | 03/15/2021 |
We want to get a table that contains the following columns: , , , and .
customer_id | first_name | last_name | |
---|---|---|---|
301 | Robert | Smith | robertsmith@example.com |
302 | Robin | Johnson | robinjohnson@example.com |
304 | Roberto | Garcia | robertogarcia@example.com |
You can use the following PostgreSQL query to achieve this:
The will match any customer record where the begins with 'Rob'. The percentage symbol '%' is a wildcard that will match any sequence of characters (including no characters). In this case, the query will return all customer records where begins with 'Rob'.
The best way to prepare for a SQL interview, besides making sure you have strong SQL fundamentals, is to practice a ton of real SQL questions that were asked in recent job interviews. Besides solving the above American Equity SQL interview questions, you should also solve the 200+ SQL questions from real Data Science & Analytics interviews which come from companies like FAANG tech companies and tech startups.
Each exercise has hints to guide you, step-by-step solutions and best of all, there's an interactive SQL code editor so you can right online code up your SQL query and have it checked.
To prep for the American Equity SQL interview it is also a great idea to solve SQL problems from other insurance companies like:
Keep up with American Equity's latest news and announcements, driving growth and innovation in the industry!
However, if your SQL skills are weak, don't worry about going right into solving questions – refresh your SQL knowledge with this interactive SQL tutorial.
This tutorial covers SQL concepts such as filtering groups with HAVING and sorting data with ORDER BY – both of these pop up routinely during American Equity SQL assessments.
In addition to SQL interview questions, the other types of questions to prepare for the American Equity Data Science Interview are:
To prepare for the American Equity Data Science interview make sure you have a deep understanding of the company's cultural values – this will be clutch for acing the behavioral interview. For the technical Data Science interviews, prepare by reading Ace the Data Science Interview. The book's got: