10 Graybar SQL Interview Questions (Updated 2024)

Updated on

October 31, 2024

Data Science, Data Engineering, and Data Analytics employees at Graybar use SQL to analyze sales trends accross different electrical products, helping them see which items are selling well and which ones need more attention. They also rely on SQL to manage their large inventory database, ensuring that products are distributed smoothly and efficiently, this is why Graybar includes SQL questions during interviews.

So, to help prep you for the Graybar SQL interview, we've collected 10 Graybar Electric SQL interview questions in this blog.

Graybar SQL Interview Questions

10 Graybar Electric SQL Interview Questions

SQL Question 1: Calculate Monthly Average Reviews Per Product

Graybar, being a Fortune 500 wholesale distributor, carries a vast number of products. Each product has a unique product id, and numerous customers review products every day. The reviews are stored in a table named "reviews".

Can you write a SQL query that calculates the average reviews per product for each month?

The table has these columns: (integer), (integer), (timestamp), (integer), and (integer - given stars by the user, between 1 and 5).

Example Input:

review_iduser_idsubmit_dateproduct_idstars
11232021-05-20 00:00:00500014
22652021-05-25 00:00:00698524
33622021-05-25 00:00:00500013
41922021-06-20 00:00:00698523
59812021-06-25 00:00:00698522

Answer:


The SQL query leverages the function to truncate to month. This results in grouping the data on a per-month, per-product basis. The function is used to calculate the average number of stars (reviews) for each product, per month. To maintain precision while displaying the average, function's output is type-casted to DECIMAL with precision 3 (allowing a maximum of 999 average stars, although in practical use stars should be between 1 and 5), and scale 2 (allowing two decimal places for more detailed averages).

For more window function practice, try this Uber SQL problem on DataLemur's interactive SQL code editor:

Uber Data Science SQL Interview Question

SQL Question 2: Top Three Salaries

Assume you had a table of Graybar employee salary data. Write a SQL query to find the top 3 highest paid employees in each department.

Graybar Example Input:

employee_idnamesalarydepartment_id
1Emma Thompson38001
2Daniel Rodriguez22301
3Olivia Smith20001
4Noah Johnson68002
5Sophia Martinez17501
8William Davis68002
10James Anderson40001

Example Input:

department_iddepartment_name
1Data Analytics
2Data Science

Example Output:

department_namenamesalary
Data AnalyticsJames Anderson4000
Data AnalyticsEmma Thompson3800
Data AnalyticsDaniel Rodriguez2230
Data ScienceNoah Johnson6800
Data ScienceWilliam Davis6800

You can solve this interview question and run your code right in DataLemur's online SQL environment:

Top 3 Department Salaries

Answer:

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.


If the solution above is tough, you can find a step-by-step solution with hints here: Top 3 Department Salaries.

SQL Question 3: How can you select unique records from a table?

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 Graybar 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_namejob_title
AkashData Analyst
BrittanyData Scientist
CarlosData Engineer
DiegoData Engineer
EvaData Analyst

Then the output from the query would be:

job_title
Data Analyst
Data Scientist
Data Engineer

Graybar Electric SQL Interview Questions

SQL Question 4: Graybar Product and Sales Analysis

Graybar, a Fortune 500 corporation, is a leader in the distribution of high quality electrical, communications, and data networking products and a provider of related supply chain management services.

Assume that you have been given two tables, and .

The table includes information about each product such as Product ID, Product Name and Product Category.

The table includes information about each sale transaction such as the Sale ID, Product ID (which product was sold), Customer ID (who purchased the product) and the Sale Date.

You need to analyze the sales data for Graybar's product categories. Your task is to write a SQL query that can help Graybar identify the top 5 product categories based on the total sales count in the year 2022.

Example Input:

product_idproduct_nameproduct_category
1Product_1Category_1
2Product_2Category_2
3Product_3Category_3
4Product_4Category_1
5Product_5Category_2

Example Input:

sale_idproduct_idcustomer_idsale_date
111001/05/2022
222002/08/2022
333003/20/2022
414004/12/2022
555005/30/2022

Answer:


The above PostgreSQL command would join the and table using the as a join key. It then groups the results by the and counts the total sales for each category for the year 2022. At last, it orders the result by in descending order and limits the result to the top 5 product categories.

SQL Question 5: What does the constraint do?

A constraint ensures that all values in a column are different. It is often used in conjunction with other constraints, such as , to ensure that the data meets certain conditions.

For example, if you had Graybar employee data stored in a database, here's some constraints you'd use:


In the Graybar employee example, the constraint is applied to the "email" field to ensure that each employee has a unique email address. This helps to ensure the integrity of the data in the database and prevents errors that could occur if two employees had the same email address.

SQL Question 6: Filter Customer Records for Graybar

Given a customer records database, write a query to filter customers who made a purchase in the last 30 days and spent more than $500. These customers should be either from the 'Construction' industry or the 'Industrial' industry. Additionally, their preferred mode of contact should not be 'Email'.

Here's some sample data for this question:

Example Input:

customer_idlast_purchase_datetotal_spendindustrypreferred_contact
001006/20/2022600ConstructionEmail
008207/10/2022700IndustrialPhone
051206/27/2022450ConstructionPhone
034507/15/2022550ConstructionMail
129007/05/2022670IndustrialPhone

Answer:

Here is a PostgreSQL query that can be used to filter the customers based on the conditions mentioned.


This solution uses the clause to filter the customer records. It uses the 'AND' and 'IN' SQL keywords to combine multiple conditions. The condition checks if the last purchase was made in the last 30 days. The condition checks if the total spend is more than $500. The condition checks if the customer is from the 'Construction' or 'Industrial' industry. The condition excludes customers whose preferred contact method is email. The '!=' operator is used to denote 'not equal to'.

SQL Question 7: Can you explain the distinction between a clustered and a non-clustered index?

Here is an example of a clustered index on the column of a table of Graybar customer transactions:


This creates a clustered index on the column, which will determine the physical order of the data rows in the table.

Here is an example of a non-clustered index on the column of the same table:


This will create a non-clustered index on the column, which will not affect the physical order of the data rows in the table.

In terms of query performance, a clustered index is usually faster for searches that return a large number of records, while a non-clustered index is faster for searches that return a small number of records. However, updates to a clustered index are slower, as they require the data rows to be physically rearranged, while updates to a non-clustered index are faster, as they only require the index data structure to be updated.

SQL Question 8: Find the Maximum Selling Product

As an assistant at Graybar, a leading distributor of electrical, communications, and data networking products, you're asked to analyze the sales data. For every month, find the product with the maximum total sales amount.

Example Input:

sales_idproduct_idsale_datesale_amount
231276501/12/2022$100
174343201/15/2022$200
279176501/20/2022$150
927339601/25/2022$140
635276502/03/2022$170
834543202/08/2022$230
942239602/11/2022$210

Example Output:

monthyearmax_sale_product_idmax_sale_sum
12022765$250
22022432$230

Answer:


This query first groups the sales by , , and and calculates the total sale amount for each group. Then, for each month and year, it finds the maximum total sale amount. The final statement joins these two intermediate results on , , and . The result is the with the maximum total sales for each month and year.

SQL Question 9: Filter Customer Records

Graybar is a Fortune 500 company, specializing in supply chain management services, and is one of the largest North American commercial lighting suppliers. Your task is to filter down their customer records database and find records of customers whose first names start with 'J' and live in 'New York'. Use the SQL keyword LIKE for this problem.

Example Input:

customer_idfirst_namelast_namecitystate
121JohnSmithSan FranciscoCalifornia
342JaneDoeNew YorkNew York
465JamesBrownNew YorkNew York
592JoeDavisAustinTexas
620JackWhiteChicagoIllinois
765JulieMoonNew YorkNew York
856JasmineBlueLos AngelesCalifornia

Example Output:

customer_idfirst_namelast_namecitystate
342JaneDoeNew YorkNew York
465JamesBrownNew YorkNew York
765JulieMoonNew YorkNew York

Answer:

The SQL query to solve this task would look as follows:


This query uses the SQL operator in conjunction with the '%' wildcard to filter for customers whose first names start with 'J'. It also uses the AND operator to further filter for customers who live in New York. This query will return a table with columns for , , , , and for any customer who matches both conditions.

SQL Question 10: What do the / operators do, and can you give an example?

The / operator is used to remove to return all rows from the first statement that are not returned by the second statement.

Note that is available in PostgreSQL and SQL Server, while is available in MySQL and Oracle (but don't stress about knowing which DBMS supports what exact commands since the interviewers at Graybar should be lenient!).

Here's a PostgreSQL example of using to find all of Graybar's Facebook video ads with more than 10k views that aren't also being run on YouTube:


If you want to retain duplicates, you can use the operator instead of . The operator will return all rows, including duplicates.

Graybar SQL Interview Tips

The best way to prepare for a Graybar SQL interview is to practice, practice, practice. Besides solving the above Graybar SQL interview questions, you should also solve the 200+ DataLemur SQL Interview Questions which come from companies like Microsoft, Google, Amazon, and tech startups.

DataLemur SQL and Data Science Interview Questions

Each problem on DataLemur has multiple hints, fully explained answers along with a discussion board to see how others solved it and crucially, there is an interactive coding environment so you can instantly run your SQL query answer and have it graded.

To prep for the Graybar SQL interview it is also useful to practice SQL problems from other industrial and electrical distribution companies like:

In case your SQL foundations are weak, don't worry about jumping right into solving questions – strengthen your SQL foundations with this free SQL for Data Analytics course.

SQL interview tutorial

This tutorial covers SQL topics like Union vs. UNION ALL and filtering data with WHERE – both of these pop up routinely during Graybar SQL interviews.

Graybar Electric Data Science Interview Tips

What Do Graybar Data Science Interviews Cover?

Beyond writing SQL queries, the other types of problems tested in the Graybar Data Science Interview are:

Graybar Data Scientist

How To Prepare for Graybar Data Science Interviews?

To prepare for Graybar Data Science interviews read the book Ace the Data Science Interview because it's got:

  • 201 interview questions taken from companies like Microsoft, Google & Amazon
  • a refresher on Python, SQL & ML
  • over 1000+ 5-star reviews on Amazon

Ace the Data Science Interview by Nick Singh Kevin Huo

Don't ignore the behavioral interview – prep for it with this guide on acing behavioral interviews.

© 2024 DataLemur, Inc

Career Resources

Free 9-Day Data Interview Crash CourseFree SQL Tutorial for Data AnalyticsUltimate SQL Interview GuideAce the Data Job Hunt Video CourseAce the Data Science InterviewBest Books for Data Analysts