Cintas employees use SQL daily for analyzing uniform rental patterns and inventory management. Which is why Cintas covers SQL query questions during interviews for Data Science and Data Engineering positions.
So, to help you study, here's 8 Cintas SQL interview questions – able to solve them?
Cintas is a company that provides a range of products and services to businesses such as uniforms, janitorial supplies, safety & compliance training, and Business Protection Services (fire and security solutions). For this question, let's assume that you're analyzing the uniform sales department.
As a data analyst, you are asked to compile a monthly report for the last year by the head office. This report needs to show the total number of uniform pieces sold each month per department and the average sale per item in each department. You have access to the sales data of each transaction.
Here is your database table named uniform_sales
.
uniform_sales
Example Input:sales_id | sales_date | department_id | num_of_uniforms | total_sale |
---|---|---|---|---|
8765 | 2021-04-10 | 001 | 10 | 200.00 |
5210 | 2021-04-28 | 002 | 50 | 450.00 |
5931 | 2021-06-16 | 001 | 30 | 660.00 |
3504 | 2021-11-25 | 002 | 60 | 540.00 |
2486 | 2022-01-18 | 001 | 20 | 400.00 |
Your task is to write a SQL query to create this report. The output should look like this. The date should be in the 'yyyymm' format.
month_year | department_id | total_num_of_uniforms | avg_sale_per_item |
---|---|---|---|
202104 | 001 | 10 | 20.00 |
202104 | 002 | 50 | 9.00 |
202106 | 001 | 30 | 22.00 |
202111 | 002 | 60 | 9.00 |
202201 | 001 | 20 | 20.00 |
In PostgreSQL, you can use the date_trunc
function to get the month and year part of a date, and avg
and to_char
function to calculate the average sale per uniform item. Here is the query that solves the problem:
SELECT to_char(date_trunc('month', sales_date), 'YYYYMM') AS month_year, department_id, SUM(num_of_uniforms) AS total_num_of_uniforms, ROUND(AVG(total_sale::float/num_of_uniforms), 2) AS avg_sale_per_item FROM uniform_sales GROUP BY month_year, department_id ORDER BY month_year, department_id;
This query first truncates the sales_date
to the month and formats it as 'YYYYMM'. Then it groups the sales by month_year
and department_id
to calculate the total number of pieces sold and the average sale per item in each month for each department. It then rounds the average sale per item to 2 decimal places using the ROUND
function.
For more window function practice, try this Uber SQL Interview Question on DataLemur's online SQL code editor:
Imagine there was a table of Cintas employee salary data. Write a SQL query to find the top three highest paid employees within each department.
employees
Example Input:employee_id | name | salary | department_id |
---|---|---|---|
1 | Emma Thompson | 3800 | 1 |
2 | Daniel Rodriguez | 2230 | 1 |
3 | Olivia Smith | 2000 | 1 |
4 | Noah Johnson | 6800 | 2 |
5 | Sophia Martinez | 1750 | 1 |
8 | William Davis | 6800 | 2 |
10 | James Anderson | 4000 | 1 |
department
Example Input:department_id | department_name |
---|---|
1 | Data Analytics |
2 | Data Science |
department_name | name | salary |
---|---|---|
Data Analytics | James Anderson | 4000 |
Data Analytics | Emma Thompson | 3800 |
Data Analytics | Daniel Rodriguez | 2230 |
Data Science | Noah Johnson | 6800 |
Data Science | William Davis | 6800 |
You can solve this question interactively on DataLemur:
We use the DENSE_RANK() window function to generate unique ranks for each employee's salary within their department, with higher salaries receiving lower ranks. Then, we wrap this up in a CTE and filter the employees with a ranking of 3 or lower.
WITH ranked_salary AS ( SELECT name, salary, department_id, DENSE_RANK() OVER ( PARTITION BY department_id ORDER BY salary DESC) AS ranking FROM employee ) SELECT d.department_name, rs.name, rs.salary FROM ranked_salary AS rs INNER JOIN department AS d ON rs.department_id = d.department_id WHERE rs.ranking <= 3 ORDER BY d.department_id, rs.salary DESC, rs.name ASC;
If the code above is tough, you can find a detailed solution here: Top 3 Department Salaries.
Also read about how Cintas generates the next generation of leadership!
DISTINCT
do?"The DISTINCT
clause in SQL allows you to select records that are unique, eliminating duplicates.
For a tangible example, say you had a table of Cintas employees:
first_name | job_title |
---|---|
Akash | Data Analyst |
Brittany | Data Scientist |
Carlos | Data Engineer |
Diego | Data Engineer |
Eva | Data Analyst |
If you were doing an HR Analytics project and you wanted to get all the unique job titles that currently worked at the company, you would write the following SQL query:
SELECT DISTINCT job_title FROM cintas_employees;
The output would give you 3 distinct job titles at Cintas:
job_title |
---|
Data Analyst |
Data Scientist |
Data Engineer |
Cintas is a company that provides specialized services to businesses, including uniform rental and supply. For each location, they maintain inventory for numerous products.
In this question, you are required to find out the average number of units used per location for each product across all the locations, during a year.
inventory
Sample Input:product_id | location_id | year | units_used |
---|---|---|---|
1001 | 001 | 2020 | 500 |
1001 | 002 | 2020 | 400 |
1001 | 003 | 2020 | 600 |
1002 | 001 | 2020 | 200 |
1002 | 002 | 2020 | 250 |
1002 | 003 | 2020 | 300 |
products
Sample Input:product_id | product_name |
---|---|
1001 | Uniform |
1002 | Towels |
product | average_units_used_per_location |
---|---|
Uniform | 500 |
Towels | 250 |
SELECT p.product_name AS product, AVG(i.units_used) AS average_units_used_per_location FROM inventory i JOIN products p ON i.product_id = p.product_id WHERE i.year = 2020 GROUP BY p.product_name;
In this query, we join the inventory table with the products table on the product_id. We then filter the records for the year 2020. Using the AVG function, we compute the average units used per location for each product. The GROUP BY clause is used to group the records by product name.
To practice a very similar question try this interactive Amazon Highest-Grossing Items Question which is similar for inventory and product analysis or this CVS Health Pharmacy Analytics (Part 1) Question which is similar for average calculation across locations.
FOREIGN KEY
constraint in SQL?A FOREIGN KEY
is a field in a table that references the PRIMARY KEY
of another table. It creates a link between the two tables and ensures that the data in the FOREIGN KEY
field is valid.
Say for example you had sales analytics data from Cintas's CRM (customer-relationship management) tool.
CREATE TABLE cintas_accounts ( account_id INTEGER PRIMARY KEY, account_name VARCHAR(255) NOT NULL, industry VARCHAR(255) NOT NULL ); CREATE TABLE opportunities ( opportunity_id INTEGER PRIMARY KEY, opportunity_name VARCHAR(255) NOT NULL, account_id INTEGER NOT NULL, FOREIGN KEY (account_id) REFERENCES cintas_accounts(account_id) );
In this example, the opportunities
table has a foreign key field called account_id
that references the "account_id" field in the cintas_accounts
table (the primary key). This helps to link the data about each opportunity to the corresponding account information in the accounts table.
This makes sure the insertion of rows in the opportunities
table that do not have corresponding entries in the cintas_accounts
table. It also helps to enforce the relationship between the two tables and ensures that data is not deleted from the cintas_accounts
table if there are still references to it in the opportunities
table.
Cintas Corporation is a business services company. Suppose you are a data analyst at Cintas and are interested in understanding the effectiveness of advertisements displayed across various websites. In particular, you are tasked to determine the click-through-rate (CTR) for each website in the past one month. Further, you are also interested in understanding the conversion rate (how many clicked ads led to a real sale).
To answer these questions, we will consider two tables - ad_clicks
and conversions
.
ad_clicks
Example Input:click_id | ad_id | date | website |
---|---|---|---|
101 | 4005 | 06/10/2022 00:00:00 | Yahoo |
102 | 3205 | 06/10/2022 00:00:00 | |
103 | 4005 | 06/16/2022 00:00:00 | Yahoo |
104 | 2002 | 06/20/2022 00:00:00 | MSN |
105 | 2002 | 06/30/2022 00:00:00 | MSN |
conversions
Example Input:conversion_id | click_id | sales_amt |
---|---|---|
39 | 101 | 150.00 |
40 | 102 | 250.00 |
41 | 104 | 120.00 |
We are interested in understanding the total click-through rate and conversion rate for each website.
WITH click_data AS ( SELECT website, COUNT(*) AS total_clicks FROM ad_clicks WHERE date BETWEEN DATE '2022-06-01' AND DATE '2022-06-30' GROUP BY website ), conversion_data AS ( SELECT c.website, COUNT(*) as total_conversions FROM conversions con JOIN ad_clicks c ON con.click_id = c.click_id WHERE c.date BETWEEN DATE '2022-06-01' AND DATE '2022-06-30' GROUP BY c.website ) SELECT cd.website, (cd.total_conversions / NULLIF(cd.total_clicks, 0)) * 100 AS conversion_rate, (cd.total_clicks / NULLIF(sum(cd.total_clicks) OVER (), 0)) * 100 AS click_through_rate FROM click_data cd LEFT JOIN conversion_data con on cd.website = con.website;
In the above solution, we first calculate the total number of ad clicks (total_clicks
) per website for a given one month period in the click_data
CTE.
Next, we calculate the total number conversions (total_conversions
) per website for the same time period in the conversion_data
CTE.
Finally, we perform a left join on these two tables on the website
column and calculate the conversion_rate
by dividing total_conversions
by total_clicks
. We also calculate the click_through_rate
by dividing total_clicks
by the sum of total_clicks
over all websites. Both rates are presented as percentages.
This query gives us both the click-through rate and conversion rate for each website where the ads were displayed. This data can be used to understand the return on investment for advertising on each website and also to guide future advertising decisions.
To solve a related problem on DataLemur's free interactive SQL code editor, attempt this SQL interview question asked by Facebook:
MINUS
/ EXCEPT
SQL commands do?Note: interviews at Cintas often aren't trying to test you on a specific flavor of SQL. As such, you don't need to exactly know that EXCEPT
is available in PostgreSQL and SQL Server, while MINUS is available in MySQL and Oracle – you just need to know the general concept!
Your answer should mention that the MINUS
/EXCEPT
operator is used to remove to return all rows from the first SELECT statement that are not returned by the second SELECT statement.
Here's a PostgreSQL example of using EXCEPT to find all of Cintas's Facebook video ads with more than 50k views that aren't also being run on YouTube:
SELECT ad_creative_id FROM cintas_facebook_ads WHERE views > 50000 AND type=video EXCEPT SELECT ad_creative_id FROM cintas_youtube_ads
If you want to retain duplicates, you can use the EXCEPT ALL operator instead of EXCEPT. The EXCEPT ALL operator will return all rows, including duplicates.
You're working for Cintas, a company that provides specialized services to businesses, including uniform rental and cleaning services. The company has a wide customer database and different service locations. Your task is to write a SQL query to filter the database so you only retrieve customers whose service location starts with 'San' (This means any location that starts with 'San' such as 'San Diego', 'San Francisco' etc.)
For simplicity, let's consider the customer records database has the following structure:
customers
Example Input:customer_id | customer_name | service_location | service_type | start_date |
---|---|---|---|---|
125 | McDonalds | San Diego | Uniform Rental | 2015-03-09 |
678 | Starbucks | New York | Cleaning Services | 2017-06-27 |
231 | In-N-Out | San Francisco | Uniform Rental | 2016-12-03 |
900 | Burger King | Los Angeles | Cleaning Services | 2017-11-14 |
754 | Subway | San Antonio | Uniform Rental | 2018-05-21 |
To filter the customers whose service location starts with 'San', you can use the SQL statement:
SELECT *
FROM customers
WHERE service_location LIKE 'San%';
This query will return the records of the customers with a service location starting with 'San'. The '%' symbol is a wildcard character that matches any sequence of characters.
customer_id | customer_name | service_location | service_type | start_date |
---|---|---|---|---|
125 | McDonalds | San Diego | Uniform Rental | 2015-03-09 |
231 | In-N-Out | San Francisco | Uniform Rental | 2016-12-03 |
754 | Subway | San Antonio | Uniform Rental | 2018-05-21 |
The SQL query has filtered the database to return only those customers whose service location starts with 'San'. It enables Cintas to easily get insight into their customers in 'San' locations and provides a starting point for further data analysis.
The key to acing a Cintas SQL interview is to practice, practice, and then practice some more!
In addition to solving the above Cintas SQL interview questions, you should also solve the 200+ tricky sql questions on DataLemur which come from companies like Amazon, Microsoft, Meta, and smaller tech companies.
Each problem on DataLemur has multiple hints, fully explained answers along with a discussion board to see how others solved it and most importantly, there's an online SQL code editor so you can right online code up your SQL query and have it graded.
To prep for the Cintas SQL interview it is also helpful to practice SQL questions from other apparel companies like:
But if your SQL query skills are weak, don't worry about going right into solving questions – go learn SQL with this SQL tutorial for Data Analytics.
This tutorial covers things like aggregate functions like SUM()/COUNT()/AVG() and WHERE vs. HAVING – both of which come up frequently in Cintas SQL assessments.
Beyond writing SQL queries, the other types of problems to practice for the Cintas Data Science Interview are:
The best way to prepare for Cintas Data Science interviews is by reading Ace the Data Science Interview. The book's got: