At Workiva, SQL is used across the company for analyzing complex financial data sets and for helping companies generate ESG reports and insights. Because of this, Workiva almost always asks SQL questions in interviews for Data Science, Analytics, and & Data Engineering jobs.
As such, to help you prepare for the Workiva SQL interview, we've collected 11 Workiva SQL interview questions – can you answer each one?
Workiva is a company that provides cloud solutions for enterprises to manage and report their financial data. They also sell a variety of software products to different customers. Your task is to analyze the performance of these software products based on user reviews.
The company maintains a 'reviews' table that logs user reviews for different software products. Each row in the table corresponds to a unique review, and captures the 'review_id', 'user_id', 'submit_date', 'product_id', and 'stars' (the rating given by the user).
Given this 'reviews' table, write a SQL query to calculate the average rating (stars) for each product on a monthly basis. Report the results in a table with the following columns: 'mth' (month of the review), 'product_id', and 'avg_stars' (average rating for the product in that month).
review_id | user_id | submit_date | product_id | stars |
---|---|---|---|---|
6171 | 123 | 06/08/2022 00:00:00 | 50001 | 4 |
7802 | 265 | 06/10/2022 00:00:00 | 69852 | 4 |
5293 | 362 | 06/18/2022 00:00:00 | 50001 | 3 |
6352 | 192 | 07/26/2022 00:00:00 | 69852 | 3 |
4517 | 981 | 07/05/2022 00:00:00 | 69852 | 2 |
This PostgreSQL query first extracts the month from the 'submit_date' using the EXTRACT function. It then groups the data by the month and 'product_id', and for each group, it calculates the average rating. The resulting table is ordered by 'mth' and 'product_id'.
mth | product_id | avg_stars |
---|---|---|
6 | 50001 | 3.50 |
6 | 69852 | 4.00 |
7 | 69852 | 2.50 |
Pro Tip: Window functions are a frequent SQL interview topic, so practice all the window function problems on DataLemur
Workiva is a company that sells hundreds of different software products around the world. As a data analyst at Workiva, you are tasked with analyzing their sales and returns to understand which products are performing best. The data is stored in two tables: and . Here is how the schema looks like:
sale_id | product_id | customer_id | sale_date | units_sold | price_per_unit |
---|---|---|---|---|---|
1372 | 987 | 154 | 2021/11/15 | 10 | 300 |
3144 | 456 | 812 | 2021/10/20 | 5 | 400 |
8739 | 321 | 596 | 2021/07/26 | 20 | 100 |
9502 | 123 | 231 | 2021/12/30 | 7 | 200 |
4582 | 123 | 812 | 2022/01/05 | 5 | 200 |
return_id | sale_id | return_date | units_returned |
---|---|---|---|
4871 | 1372 | 2021/12/30 | 2 |
5116 | 8739 | 2021/08/15 | 5 |
3662 | 9502 | 2022/01/10 | 1 |
Your task is to create a SQL query that returns a table showing the total sales and total returns for each product by month. It should include the columns , , and . The column should be in the format 'YYYY-MM'.
In this query, we are using the function to handle values that might arise in case a product has sales but no returns in a month (or vice versa). We are also joining and tables on to track the returns against the right product. We are calculating the total sales and total returns based on and respectively. We use to group the results by month.
{#Question-3}
The CHECK constraint is used to set a rule for the data in a column. If a row is inserted or updated and the data in the column does not follow the rule specified by the CHECK constraint, the operation will be unsuccessful.The CHECK constraint is often used in conjunction with other constraints, such as NOT NULL or UNIQUE.
You might consider implementing the CHECK constraint in your database if you want to ensure that certain data meets specific conditions. This can be helpful for maintaining the quality and reliability of your data.
For example, you might use a CHECK constraint to ensure that a column contains only positive numbers, or that a date is within a certain range.
As a data analyst at Workiva, your task is to manage the customer records database. The marketing team needs a list of customers for a promotional campaign. Specifically, they are interested in customers who:
Your query should return a list of users who meet all the above conditions, including their username, email address, signup date, subscription type, and location.
Please use the table as a reference.
customer_id | username | signup_date | subscription_status | subscription_type | location | |
---|---|---|---|---|---|---|
101 | adamsmith | adamsmith@gmail.com | 06/15/2019 | Active | Premium | USA |
102 | emilydavies | emilydav@gmail.com | 01/20/2020 | Active | Basic | USA |
103 | johndoe | johndoe@yahoo.com | 03/01/2021 | Inactive | Pro | UK |
104 | anacosta | anacosta@hotmail.com | 04/10/2020 | Active | Pro | USA |
105 | steveperry | steveperry@gmail.com | 02/10/2022 | Active | Premium | Canada |
This PostgreSQL query filters the table based on the requirement: customers who signed up after January 1, 2020, have active subscription status, and their location is the USA. Therefore, based on the sample data, the output would be:
username | signup_date | subscription_type | location | |
---|---|---|---|---|
emilydavies | emilydav@gmail.com | 01/20/2020 | Basic | USA |
anacosta | anacosta@hotmail.com | 04/10/2020 | Pro | USA |
Using a join in SQL, you can retrieve data from multiple tables and merge the results into a single table.
In SQL, there are four distinct types of JOINs. To demonstrate each kind, Imagine you had two database tables: an table that contains data on Google Ads keywords and their bid amounts, and a table with information on product sales and the Google Ads keywords that drove those sales.
: An INNER JOIN retrieves rows from both tables where there is a match in the shared key or keys. For example, an INNER JOIN between the table and the table could be performed using the keyword column as the shared key. This would retrieve only the rows where the keyword in the table matches the keyword in the table.
: A LEFT JOIN retrieves all rows from the left table (in this case, the table) and any matching rows from the right table (the Sales table). If there is no match in the right table, values will be returned for the right table's columns.
: A RIGHT JOIN retrieves all rows from the right table (in this case, the Sales table) and any matching rows from the left table (the table). If there is no match in the left table, values will be returned for the left table's columns.
: A FULL OUTER JOIN retrieves all rows from both tables, regardless of whether there is a match in the shared key or keys. If there is no match, values will be returned for the columns of the non-matching table.
As a project manager at Workiva, you are interested in tracking how long projects are taking. You want to find the average duration of all projects in each department.
In the above query, we use the to calculate the duration of each project in days. The AVG function then calculates the average duration for each department. The output gives us the average project duration in days for each department.
To practice a very similar question try this interactive Amazon Highest-Grossing Items Question which is similar for needing to perform calculations for grouped data or this Facebook Average Post Hiatus (Part 1) Question which is similar for needing to calculate durations between dates.
Some similarities between unique and non-unique indexes include:
Some differences between unique and non-unique indexes include:
Workiva uses various digital advertising platforms to promote their products. Each ad click redirects the user to a landing page, and if the user finds the product interesting, they might add the product to their cart.
We have two tables here: which records every click on the ads with the ad_id, user_id, click_time and which records every product added to the cart with the user_id, add_time and product_id.
Calculate the Click-through Conversion rate, which is the number of users who added the product to the cart after clicking on an ad, divided by the total number of clicks each ad has received.
ad_id | user_id | click_time |
---|---|---|
A1 | 123 | 06/08/2022 00:00:00 |
A2 | 265 | 06/10/2022 00:00:00 |
A1 | 982 | 06/15/2022 00:10:00 |
A2 | 192 | 07/26/2022 00:15:00 |
A1 | 981 | 07/05/2022 00:00:00 |
user_id | add_time | product_id |
---|---|---|
123 | 06/08/2022 00:05:00 | P50001 |
265 | 06/10/2022 00:05:00 | P69852 |
362 | 06/18/2022 00:00:00 | P50001 |
192 | 07/26/2022 00:20:00 | P69852 |
982 | 06/15/2022 00:15:00 | P50001 |
ad_id | click_through_conversion_rate |
---|---|
A1 | 0.666 |
A2 | 1.000 |
The CTEs are used to gather the click and add actions per ad. We join the two tables based on the user_id and make sure that click_time is less or equal to add_time. In the final query, we obtain the conversion rate by dividing the number of adds by the number of clicks per ad. The LEFT JOIN ensures we get all ads, even those without any add_to_cart action.
To practice another question about calculating rates, try this SQL interview question from TikTok within DataLemur's online SQL coding environment:
Workiva, a leading provider of enterprise cloud solutions, sells software licenses to different companies. Write an SQL query that provides a monthly breakdown for the average amount of licenses sold per month.
This query extracts the month from the purchase date of each record in the table and groups the records by this month value. For each group of records (i.e., each month), it calculates the average number of licenses sold rounding to two decimal places. The results are returned in ascending order by month.
Imagine you are organizing a party and have two database tables: one table of people you want to invite and another list of food items you want to serve.
A cross join would be like inviting every person on your list to the party and serving them every food item on the menu, regardless of whether they like the food or not. So, if you had 10 people on your invite list and 5 food items on the menu, you would generate all 50 different combinations of people and food (10 x 5 = 50).
On the other hand, a natural join would be like inviting only the people who like the food items on the menu (based on doing a inner/left/right/outer JOIN on a common key like ).
Workiva's customers come from a wide range of industries, including technology, education, healthcare, and more. As an SQL developer, you'll often be asked to filter customer data based on certain criteria.
Consider the table below. Write a SQL query to find customers whose begins with the letter 'W', hailing from the 'Technology' industry and having their domain as '@workiva.com'.
customer_id | first_name | last_name | contact_email | industry | company_name |
---|---|---|---|---|---|
6171 | Felicia | Doe | felicia.doe@workiva.com | Technology | Workiva |
7802 | Alice | Smith | alice.smith@othertech.com | Technology | WeboTech |
5293 | John | White | john.white@workiva.com | Technology | Workiva |
6352 | Avery | Johnson | avery.johnson@gmail.com | Healthcare | WellnessCorp |
4517 | Rachel | James | rachel.james@workiva.com | Education | Worldwide Educators |
customer_id | first_name | last_name | contact_email | industry | company_name |
---|---|---|---|---|---|
6171 | Felicia | Doe | felicia.doe@workiva.com | Technology | Workiva |
5293 | John | White | john.white@workiva.com | Technology | Workiva |
This query filters the table to return records where the begins with the letter 'W', the is 'Technology', and the ends with '@workiva.com'. This allows us to find customers who work in the technology industry for companies with names starting with 'W' and use their Workiva email as the contact email.
The key to acing a Workiva SQL interview is to practice, practice, and then practice some more! Besides solving the earlier Workiva SQL interview questions, you should also solve the 200+ DataLemur SQL Interview Questions which come from companies like Facebook, Google and unicorn tech startups.
Each interview question has multiple hints, step-by-step solutions and most importantly, there is an interactive coding environment so you can instantly run your SQL query and have it graded.
To prep for the Workiva SQL interview you can also be wise to solve interview questions from other tech companies like:
But if your SQL query skills are weak, forget about going right into solving questions – strengthen your SQL foundations with this free SQL tutorial.
This tutorial covers SQL topics like functions like SUM()/COUNT()/AVG() and INTERCEPT/EXCEPT – both of which come up routinely during Workiva interviews.
Besides SQL interview questions, the other question categories tested in the Workiva Data Science Interview are:
The best way to prepare for Workiva Data Science interviews is by reading Ace the Data Science Interview. The book's got: