Workday almost always evaluates jobseekers on SQL query questions in interviews for Data Science and Data Engineering positions. They do this because at Workday, SQL is used to analyze product usage data generated from the company's suite of HR, Finance, and Payroll products. SQL also powers the Workforce Analytics platform they have.
So, to help you prepare for the Workday SQL Interview, we've curated 11 Workday SQL interview questions to practice, which are similar to recently asked questions at Workday!
Suppose you are a data analyst in Workday's Solutions Engineering & Implementation team, and have been tasked by a customer to analyze employee salaries. Your client wants to compare the average salaries of each department to have a better understanding of the payroll distribution. Write a SQL query to calculate the average salary per department.
employee_id | first_name | last_name | department | salary |
---|---|---|---|---|
1756 | Jane | Smith | Engineering | 80000 |
2853 | John | Doe | HR | 60000 |
6478 | Matt | Jones | Engineering | 90000 |
1923 | Sara | Davis | HR | 65000 |
5241 | Mike | Brown | Marketing | 70000 |
3852 | Julia | Johnson | Engineering | 85000 |
department | avg_salary |
---|---|
Engineering | 85000 |
HR | 62500 |
Marketing | 70000 |
This SQL query achieves the desired result by using a window function ( OVER ). It calculates the average salary for each department. The clause is used to divide the data into partitions (groups) that share the same . Then, the window function is applied to each partition separately.
Workday is a company that provides human capital management, financial management applications, and workforce management applications. Given that, let's consider a scenario where they want to analyze employee attendance statistics.
The HR department would like to have a report showing the total working days and the days with vacation for each employee for a given month. They have two tables and .
Here is their structure:
employee_id | first_name | last_name |
---|---|---|
123 | Jane | Smith |
456 | John | Doe |
789 | Emily | Johnson |
timesheet_id | employee_id | work_date | hours_worked | leave_status |
---|---|---|---|---|
1 | 123 | 2022-06-01 | 8 | WORKED |
2 | 123 | 2022-06-02 | 8 | WORKED |
3 | 123 | 2022-06-03 | 0 | VACATION |
4 | 456 | 2022-06-01 | 8 | WORKED |
5 | 456 | 2022-06-02 | 0 | VACATION |
6 | 789 | 2022-06-01 | 8 | WORKED |
Provide a PostgreSQL query that will output a table with columns , , , .
This query first combines the first_name and last_name fields to create a full name, employee_name. It then formats the work_date to 'Mon-YYYY' format to get the month and year. The counting of total working days and vacation days are done via a conditional sum or what is often referred to as a sum aggregation with a case statement. The result is then grouped by employee_name and month_year. The order by clause sorts the result first by employee_name and then by month_year to provide a clean visual.
To practice a related SQL problem on DataLemur's free interactive SQL code editor, try this SQL interview question asked by Facebook:
A cross-join, also known as a cartesian join, is like a mad scientist's laboratory experiment gone wild. It takes two tables and mixes them together to create a crazy new table with every possible combination of rows from the original tables.
Here's an example:
If you have 20 products and 10 colors, that's 200 rows right there! Cross-joins are great for generating all possible combinations, but they can also create really big tables if you're not careful. Just like a mad scientist, use your powers wisely!
As an HR analytics company, Workday might be interested in tracking how many leave days employees use per year, on average, to monitor employee wellness and understand the company’s operations.
Given the and tables below, write a SQL query to find the average number of leave days taken per employee per year.
employee_id | first_name | last_name | start_date |
---|---|---|---|
1 | John | Doe | 2019-05-14 |
2 | Jane | Smith | 2020-01-01 |
3 | Sarah | Johnson | 2020-07-01 |
4 | James | Brown | 2021-01-01 |
leave_id | employee_id | leave_start_date | leave_end_date |
---|---|---|---|
1 | 1 | 2020-05-18 | 2020-05-22 |
2 | 2 | 2021-08-01 | 2021-08-15 |
3 | 3 | 2021-12-20 | 2022-01-03 |
4 | 1 | 2021-05-17 | 2021-05-21 |
5 | 4 | 2022-01-15 | 2022-01-22 |
The table contains and , which define the start and end of an employee’s leave, respectively.
This query uses the command to merge the and tables based on matching .
The expression retrieves the year from .
The function then calculates the average number of leave days, where the number of leave days is determined as ( - + 1) to include the first day of the leave.
Finally, the keyword groups the result by and Year while the keyword sorts the result by and then by Year.
A join in SQL combines rows from two or more tables based on a shared column or set of columns. To demonstrate the difference between a and , say you had a table of Workday orders and Workday customers.
LEFT JOIN: A retrieves all rows from the left table (in this case, the Orders table) and any matching rows from the right table (the Customers table). If there is no match in the right table, NULL values will be returned for the right table's columns.
RIGHT JOIN: A retrieves all rows from the right table (in this case, the Customers table) and any matching rows from the left table (the Orders table). If there is no match in the left table, NULL values will be returned for the left table's columns.
Workday, a company providing enterprise cloud applications for human resources and finance, tracks every click a user does in their ecosystem. Specifically, they're interested in understanding the clickthrough conversion rate from the point a user views a digital product, to the point they add it to their cart. To perform this analysis, Workday has captured key data in two tables: 'view_logs' and 'add_to_cart_logs'.
The 'view_logs' table records whenever a user views a product, and has three columns: (integer), (integer), and (integer).
Meanwhile, the 'add_to_cart_logs' table records whenever a user adds a product to their cart, and also has three columns: (integer), (integer), and (integer).
You need to write a PostgreSQL query that calculates the clickthrough conversion rate (i.e., the number of users who added a product to their cart after viewing it divided by the total number of users who viewed the product) for each product.
log_id | user_id | product_id |
---|---|---|
101 | 767 | 2309 |
102 | 292 | 2309 |
103 | 602 | 4821 |
104 | 499 | 3417 |
105 | 555 | 3417 |
log_id | user_id | product_id |
---|---|---|
501 | 767 | 2309 |
502 | 292 | 2309 |
503 | 602 | 4821 |
504 | 555 | 3417 |
505 | 382 | 3920 |
This SQL query makes use of a LEFT JOIN to combine 'view_logs' and 'add_to_cart_logs' based on the user_id and product_id. In the SELECT clause, we calculate the clickthrough conversion rate for each product by dividing the number of unique users who added the product to their cart by the total number of unique users who viewed the product. We make use of the GROUP BY clause to accomplish this calculation for each product separately. This will give Workday the clickthrough conversion rate for each of their products.
To solve a related SQL interview question on DataLemur's free online SQL code editor, solve this SQL interview question asked by Facebook:
The keyword removes duplicates from a query.
Suppose you had a table of Workday customers, and wanted to figure out which cities the customers lived in, but didn't want duplicate results.
table:
name | city |
---|---|
Akash | SF |
Brittany | NYC |
Carlos | NYC |
Diego | Seattle |
Eva | SF |
Faye | Seattle |
You could write a query like this to filter out the repeated cities:
Your result would be:
city |
---|
SF |
NYC |
Seattle |
As a large Human Capital Management (HCM) company, Workday needs to keep track of all the employees, their salaries, and departments to manage the payroll better. As part of the analytics team, you've been tasked to write a SQL query to calculate the total payroll and average salary per department in the organization.
emp_id | department_id | salary |
---|---|---|
1 | 100 | 1200 |
2 | 100 | 1000 |
3 | 200 | 1500 |
4 | 200 | 1300 |
5 | 300 | 1800 |
dept_id | dept_name |
---|---|
100 | Marketing |
200 | Sales |
300 | Engineering |
dept_name | total_payroll | avg_salary |
---|---|---|
Marketing | 2200 | 1100 |
Sales | 2800 | 1400 |
Engineering | 1800 | 1800 |
This query joins and tables based on the department id, and then calculates the total sum of salaries () and average per department (), as specified by .
To practice a similar problem about calculating rates, solve this SQL interview question from TikTok on DataLemur's interactive coding environment:
As part of your role as a database manager at Workday, you need to find all the employees that work in a specific department based on a partial name match. The HR team often needs this information to quickly identify the relevant employees as part of ongoing staff management. You have access to the 'employees' table, with the following structure.
emp_id | first_name | last_name | join_date | department |
---|---|---|---|---|
001 | John | Doe | 01/10/2021 | Software Engineering |
002 | Jane | Smith | 03/12/2020 | Data Analysis |
003 | David | Brown | 05/15/2019 | Software Engineering |
004 | Sarah | Johnson | 07/21/2021 | Data Analysis |
005 | Michael | Miller | 09/16/2020 | Human Resources |
Based on the provided 'employees' table, can you write a SQL query that will return all employees that work in a department containing the word 'Software'?
This SQL query uses the operator to match any records from the table where the field contains the word 'Software'. The '%' either side of 'Software' means that there can be any characters, or none, before and after 'Software'.
For our sample data, this SQL query will return the records of employees 'John Doe' and 'David Brown', as they work in the 'Software Engineering' department.
is used to combine the output of multiple statements into one big result!
For a concrete example, say you were a Data Analyst supporting the Sales Analytics team at Workday, and data on potential sales leads lived in both Salesforce CRM and Hubspot. To write a query to analyze leads created after 2023 started, across both CRMs, you could use in the following way:
"
In Workday, the HR would like to calculate a bonus for employees based on their performances. If an employee has completed over 120 hours in a month, they will receive a 5% bonus. If they completed over 140 hours, they receive a 10% bonus. For other hours, the bonus is calculated as hours * rate * 0.01. Use the SQL functions ABS(), ROUND(), SQRT(), MOD(), POWER() to calculate the total bonus for each employee.
employee_id | month | year | hours_worked |
---|---|---|---|
101 | 1 | 2022 | 125 |
102 | 1 | 2022 | 130 |
103 | 1 | 2022 | 145 |
101 | 2 | 2022 | 122 |
102 | 2 | 2022 | 140 |
103 | 2 | 2022 | 130 |
employee_id | rate |
---|---|
101 | 20 |
102 | 25 |
103 | 30 |
employee_id | month | year | bonus |
---|---|---|---|
101 | 1 | 2022 | 125 |
102 | 1 | 2022 | 162.5 |
103 | 1 | 2022 | 435 |
101 | 2 | 2022 | 122 |
102 | 2 | 2022 | 350 |
103 | 2 | 2022 | 195 |
In the above query, we are using a JOIN to combine the hours and rates for each employee. Then based on the conditions provided, we are calculating the bonus using a CASE statement by referring to the hours_worked, rate and using the mentioned mathematical functions. We use ROUND to make sure the bonus is a round figure and POWER to calculate the 0.01 multiplication factor.
To practice a related problem on DataLemur's free online SQL code editor, solve this Facebook SQL Interview question:
The key to acing a Workday SQL interview is to practice, practice, and then practice some more! Beyond just solving the earlier Workday SQL interview questions, you should also solve the 200+ FAANG SQL Questions on DataLemur which come from companies like Google, Uber, and Microsoft.
Each SQL question has hints to guide you, detailed solutions and best of all, there's an interactive coding environment so you can right in the browser run your SQL query answer and have it graded.
To prep for the Workday SQL interview it is also a great idea to solve interview questions from other tech companies like:
But if your SQL query skills are weak, don't worry about going right into solving questions – improve your SQL foundations with this DataLemur SQL Tutorial.
This tutorial covers topics including filtering on multiple conditions using AND/OR/NOT and cleaning text data – both of these come up frequently in SQL interviews at Workday.
For the Workday Data Science Interview, in addition to SQL query questions, the other types of questions which are covered:
To prepare for Workday Data Science interviews read the book Ace the Data Science Interview because it's got:
You can also look for insights on their engineering blog, like this article on how they use AWS Aurora Databases.