At Encompass Health, SQL is used for extracting and analyzing patient health data to enhance the quality of care provided to patients. They also used SQL to manage large amounts of healthcare databases, making it easier for healthcare professionals to access critical data quickly and efficiently, that is why Encompass Health includes SQL coding questions in interviews for Data Analyst, Data Science, and BI positions.
So, to help you prepare, we've collected 11 Encompass Health SQL interview questions – can you solve them?
Encompass Health offers inpatient rehabilitation, home health, and hospice services. For their business, a power user (or VIP user, or whale user) might be a patient who frequently utilizes their services.
As an interviewee, you are asked to write a SQL query that identifies customers who have had the highest number of services (across all types of services) in the past one year.
For this question, we will assume that Encompass Health maintains two tables:
patient_id | name | registration_date |
---|---|---|
1 | John Doe | 01-01-2018 |
2 | Jane Doe | 01-04-2017 |
3 | Emily Smith | 01-01-2019 |
service_id | patient_id | service_type | service_date |
---|---|---|---|
1001 | 1 | Inpatient Rehab | 01-01-2020 |
1002 | 1 | Home Health | 01-03-2020 |
1003 | 2 | Hospice | 01-02-2020 |
1004 | 2 | Inpatient Rehab | 01-08-2020 |
1005 | 3 | Home Health | 02-01-2020 |
1006 | 1 | Home Health | 04-01-2020 |
You can make use of the following PostgreSQL query:
This SQL query identifies the top 10 patients who have availed the highest number of services in the past 1 year. It joins the and tables on the column, filters for services utilized in the past one year, counts the number of services per patient, and finally orders the result in decreasing order of service count. The query uses a to include all patients even if they do not appear in the table, but this may be changed to a if only patients who appear in the table are of interest.
To solve a related customer analytics question on DataLemur's free online SQL coding environment, try this Microsoft Azure Cloud SQL Interview Question:
Dive into Encompass Health's newsroom to learn about their commitment to rehabilitation and innovative healthcare solutions! Gaining insights from their updates can help you understand the evolving landscape of patient care in rehabilitation services.
Given a table of Encompass Health employee salary information, write a SQL query to find all employees who make more than their direct boss.
employee_id | name | salary | department_id | manager_id |
---|---|---|---|---|
1 | Emma Thompson | 3800 | 1 | |
2 | Daniel Rodriguez | 2230 | 1 | 10 |
3 | Olivia Smith | 8000 | 1 | 8 |
4 | Noah Johnson | 6800 | 2 | 8 |
5 | Sophia Martinez | 1750 | 1 | 10 |
8 | William Davis | 7000 | 2 | NULL |
10 | James Anderson | 4000 | 1 | NULL |
employee_id | employee_name |
---|---|
3 | Olivia Smith |
This is the output because Olivia Smith earns $8,000, surpassing her manager, William Davis who earns 7,800.
Try this problem interactively on DataLemur:
First, we perform a SELF-JOIN where we treat the first table () as the managers' table and the second table () as the employees' table. Then we use a clause to filter the results, ensuring we only get employees whose salaries are higher than their manager's salary.
If the solution above is confusing, you can find a step-by-step solution here: Highly-Paid Employees.
A cross-join, also known as a cartesian join, is a JOIN that produces the cross-product of two tables. In a cross-join, each row from the first table is matched with every row from the second table, resulting in a new table with a row for each possible combination of rows from the two input tables.
Suppose you were building a Neural Network ML model, that tried to score the probability of a customer buying a Encompass Health product. Before you started working in Python and Tensorflow, you might want to do some Exploratory Data Analysis (EDA) in SQL, and generate all pairs of customers and Encompass Health products.
Here's a cross-join query you could use to find all the combos:
Cross-joins are great for generating all possible combinations, but they can also create really big tables if you're not careful. For example, if you had 10,000 potential customers, and Encompass Health had 500 different product SKUs, you'd get 5 million rows as a result!!
Encompass Health is a company that provides inpatient rehabilitation, home health, and hospice services. Suppose that you are given a table of patient discharges, and you are tasked to analyze the average recovery time by month for each state using SQL window functions.
Here is the data you have:
discharge_id | patient_id | state | admission_date | discharge_date |
---|---|---|---|---|
1234 | 5678 | Alabama | 2022-04-01 | 2022-04-15 |
2345 | 6789 | Alabama | 2022-04-03 | 2022-04-20 |
3456 | 7890 | Alabama | 2022-05-01 | 2022-05-11 |
4567 | 8901 | California | 2022-04-10 | 2022-04-15 |
5678 | 9012 | California | 2022-04-20 | 2022-04-30 |
6789 | 2345 | California | 2022-05-05 | 2022-05-15 |
and are both in 'YYYY-MM-DD' format. Recovery time is computed as the number of days between and .
Your task is to write a PostgreSQL query that computes the average recovery time by month and by state.
This PostgreSQL query uses the window function . For each row, it computes the average difference in days between and , grouping the rows by both state and the month of the . The function is used to get the month at which the occurred, and the is used to compute the number of days that the patient stayed at the facility. The clause then orders the results first by state, then by month.
Pro Tip: Window functions are a frequent SQL interview topic, so practice all the window function problems on DataLemur
Some similarities between unique and non-unique indexes include:
Some differences between unique and non-unique indexes include:
Encompass Health wishes to better understand their service quality across different health facilities. They ask you to provide them with the average ratings received by each health facility on a monthly basis.
You are given access to two tables. The table includes a rating id, a patient id, the submit date of the review, the id of the health facility, and the star ratings given. Meanwhile, the table consists of a facility id and its corresponding name.
rating_id | patient_id | submit_date | facility_id | stars |
---|---|---|---|---|
1111 | 567 | 08/05/2023 00:00:00 | 001 | 5 |
1112 | 890 | 08/10/2023 00:00:00 | 002 | 3 |
1113 | 123 | 08/12/2023 00:00:00 | 001 | 4 |
1114 | 456 | 08/15/2023 00:00:00 | 002 | 2 |
1115 | 789 | 08/20/2023 00:00:00 | 001 | 3 |
facility_id | facility_name |
---|---|
001 | Encompass Health Hospital A |
002 | Encompass Health Hospital B |
mth | facility_name | avg_stars |
---|---|---|
8 | Encompass Health Hospital A | 4.00 |
8 | Encompass Health Hospital B | 2.50 |
The PostgreSQL query to get the solution would look something like this:
The solution first joins the and tables on the . It then groups the data based on the month of the and , and calculates the average for each group. The result is then sorted by and in descending order to get the output.
To discover records in one table that are not present in another, you can utilize a and filter out any values in the right-side table.
For example, say you had a table of Encompass Health customers and a 2nd table of all purchases made with Encompass Health. To find all customers who did not make a purchase, you'd use the following
This query fetches all rows from the customers table, along with any rows that match in the purchases table. If there is no matching row in the purchases table, values will be returned for all of the right table's columns. The clause then filters out any rows where the column is NULL, leaving only customers who have not made a purchase.
For Encompass Health, a key metric could be the average patient recovery time. Here's a question to test your knowledge of function.
"How would you determine the average number of days it takes for a patient to recover, per diagnosis, in the last year?"
Please use the following sample data:#### Example Input:
patient_id | admit_date | discharge_date | diagnosis |
---|---|---|---|
1123 | 2021-01-05 | 2021-01-18 | Stroke |
2144 | 2021-03-10 | 2021-04-07 | Cardiac Surgery |
3154 | 2021-07-20 | 2021-08-10 | Stroke |
4127 | 2021-10-05 | 2021-10-15 | Cardiac Surgery |
5362 | 2021-12-01 | 2022-01-10 | Stroke |
This query calculates the average recovery time ( - ) for patients admitted between 2021-01-01 and 2022-01-01. It groups the result by diagnosis to get the average recovery time per diagnosis.
To practice a very similar question try this interactive Amazon Average Review Ratings Question which is similar for calculating average metrics or this Facebook Average Post Hiatus (Part 1) Question which is similar for determining averages over a time period.
Encompass Health is interested in understanding the effectiveness of their digital health services advertisements. For each advertisement, we have information on how many times it was displayed and how many times it was clicked through to the product page.
The task is to calculate the click-through-rate (CTR) for each ad. CTR is calculated as the number of clicks an ad receives divided by the number of times the ad is shown, multiplied by 100% (to get the percentage).
Here's some sample data:
ad_id | displayed_count | clicked_count |
---|---|---|
1 | 10000 | 500 |
2 | 20000 | 2500 |
3 | 15000 | 250 |
4 | 30000 | 4500 |
5 | 50000 | 20000 |
The task: Write a SQL query that calculates the CTR for each ad.
ad_id | displayed_count | clicked_count | click_through_rate |
---|---|---|---|
1 | 10000 | 500 | 5.00 |
2 | 20000 | 2500 | 12.50 |
3 | 15000 | 250 | 1.67 |
4 | 30000 | 4500 | 15.00 |
5 | 50000 | 20000 | 40.00 |
The query calculates the Click-Through-Rate for each ad by dividing the by and then multiplying by 100 to get the percentage. The function is used to convert into a float to ensure accurate division results.
To solve a similar SQL problem on DataLemur's free online SQL code editor, solve this Facebook SQL Interview question:
Stored procedures are like functions in Python – they can accept input params and return values, and are used to encapsulate complex logic.
For example, if you worked as a Data Analyst in support of the Marketing Analytics team at Encompass Health, a common task might be to find the conversion rate for your ads given a specific time-frame. Instead of having to write this query over-and-over again, you could write a stored procedure like the following:
To call this stored procedure, you'd execute the following query:
Encompass Health offers different health services and treatments to patients. They have a system that tracks patients from the time they start treatment to when they finish their treatment and gain recovery. The intent is to monitor and find an average of how long each of their services takes to effectively heal a patient. Therefore, your task is to write a SQL query to determine the average recovery time per service.
recovery_id | patient_id | treatment_id | start_date | end_date |
---|---|---|---|---|
6012 | 345 | 1001 | 06/15/2022 | 06/25/2022 |
7210 | 926 | 2002 | 06/08/2022 | 06/19/2022 |
5028 | 568 | 1001 | 06/20/2022 | 07/04/2022 |
6096 | 782 | 3003 | 06/22/2022 | 07/06/2022 |
4254 | 298 | 2002 | 06/29/2022 | 07/14/2022 |
treatment | average_recovery_days |
---|---|
1001 | 12.5 |
2002 | 13.0 |
3003 | 14.0 |
In this query, we first extract the number of days between the and the for each recovery record. We then use the function to calculate the average number of recovery days for each treatment (by grouping the records by ).
Assuming that you've already got basic SQL skills, the next best tip we have to prepare for the Encompass Health SQL interview is to solve as many practice SQL interview questions as you can! Beyond just solving the above Encompass Health SQL interview questions, you should also solve the 200+ SQL questions from real Data Science & Analytics interviews which come from companies like Google, Uber, and Microsoft.
Each exercise has hints to guide you, full answers and crucially, there's an interactive coding environment so you can instantly run your SQL query answer and have it executed.
To prep for the Encompass Health SQL interview it is also a great idea to solve SQL questions from other healthcare and pharmaceutical companies like:
However, if your SQL skills are weak, don't worry about going right into solving questions – improve your SQL foundations with this free SQL tutorial.
This tutorial covers SQL topics like filtering data with WHERE and filtering strings based on patterns – both of these show up frequently during SQL job interviews at Encompass Health.
Beyond writing SQL queries, the other types of problems tested in the Encompass Health Data Science Interview are:
To prepare for the Encompass Health Data Science interview make sure you have a firm understanding of the company's values and company principles – this will be clutch for acing the behavioral interview. For technical interviews prepare by reading Ace the Data Science Interview. The book's got: