At Lockheed Martin, SQL is crucial for querying aerospace supply-chain databases, and for analyzing sales of it's different products sold. Because of this, Lockheed Martin frequently asks SQL coding questions in interviews for Data Science, Data Engineering and Data Analytics jobs.
In case you're preparing for a SQL Interview, we've curated 10 Lockheed Martin SQL interview questions to practice, which are similar to recently asked questions at Lockheed Martin – able to answer them all?
As an interviewee, you are given two SQL tables. One, "orders", is a record of all purchases made by Lockheed Martin customers, and the other, "users", contains details about the customers. Your task is to write a SQL query that identifies the top 10 customers who have generated the highest revenue for Lockheed Martin in the year 2022.
user_id | name | country |
---|---|---|
123 | Navy | USA |
265 | SpaceX | USA |
362 | DoD | USA |
192 | Pentagon | USA |
981 | CIA | USA |
order_id | user_id | order_date | product_id | price |
---|---|---|---|---|
6171 | 123 | 06/08/2022 00:00:00 | 101 | 1500 |
7802 | 265 | 06/10/2022 00:00:00 | 102 | 2000 |
5293 | 362 | 06/18/2022 00:00:00 | 103 | 3000 |
6352 | 192 | 07/26/2022 00:00:00 | 101 | 1500 |
4517 | 981 | 07/05/2022 00:00:00 | 104 | 5000 |
This SQL query first joins the two tables on the column "user_id". After that, it applies a filter to include only transactions made in the year 2022. It then groups the rows by "user_id" and "name", calculates the total revenue by each group with the SUM function, and orders them in descending order of revenue. Finally, it selects the top 10 customers.
To practice a related super-user data analysis question on DataLemur's free interactive SQL code editor, try this Microsoft Teams Power User SQL Interview Question:
Assume that Lockheed owns multiple manufacturing plants, each responsible for manufacturing a variety of aerospace products.
The Director of Manufacturing Operations wants to analyze the monthly production output of each product at each manufacturing plant. The objective is to identify the most and least productive manufacturing plants each month based on the total quantity of each product manufactured. The director is also interested in the year-over-year changes in the number of each product manufactured at each plant.
Using the and tables below, create an SQL query that provides the total number of each product manufactured at each plant, month by month, along with comparisons to the same month in the previous year.
product_id | manufacturing_plant | manufacture_date | quantity |
---|---|---|---|
PR001 | P001 | 01/04/2021 | 330 |
PR002 | P001 | 01/04/2021 | 200 |
PR001 | P002 | 01/24/2021 | 400 |
PR002 | P002 | 01/24/2021 | 150 |
PR001 | P001 | 02/14/2021 | 280 |
PR002 | P001 | 02/14/2021 | 230 |
PR001 | P002 | 01/25/2022 | 350 |
PR002 | P002 | 01/25/2022 | 270 |
mth | yr | product_id | plant | qty | qty_last_year |
---|---|---|---|---|---|
1 | 2021 | PR001 | P001 | 330 | Null |
1 | 2021 | PR002 | P001 | 200 | Null |
1 | 2021 | PR001 | P002 | 400 | Null |
1 | 2021 | PR002 | P002 | 150 | Null |
2 | 2021 | PR001 | P001 | 280 | Null |
2 | 2021 | PR002 | P001 | 230 | Null |
1 | 2022 | PR001 | P002 | 350 | 730 |
1 | 2022 | PR002 | P002 | 270 | 350 |
This SQL query first groups the raw data by month, year, product ID, and manufacturing plant, and calculates the sum of quantity across each group. The window function then provides access to more than one row of a table at the same time without the need for a self-join. It's used here to retrieve the sum of quantity from the previous year (or the preceding row in the ordered partition), enabling a straightforward comparison of current and previous year monthly production quantities. If no data is available for the previous year, NULL is returned.
For more window function practice, solve this Uber SQL problem within DataLemur's interactive coding environment:
The keyword removes duplicates from a query.
Suppose you had a table of Lockheed Martin 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 project manager at Lockheed Martin, you have access to a database with records of all engineers on your team. Each engineer has a profile containing details such as their employee ID, name, age, department, years of experience, and security clearance level.
For a new project that requires engineers who are under 30 years old, have at least 5 years of experience, and have a top secret security clearance level, write a SQL query to filter these specific engineers from the database.
emp_id | name | age | department | years_experience | security_clearance |
---|---|---|---|---|---|
101 | Jane | 28 | Aerospace | 8 | Top Secret |
102 | Dave | 32 | Defense | 6 | Secret |
103 | Clara | 29 | Aerospace | 4 | Top Secret |
104 | John | 27 | Cyber | 6 | Top Secret |
105 | Brian | 30 | Aeronautics | 7 | Secret |
emp_id | name | age | department | years_experience | security_clearance |
---|---|---|---|---|---|
101 | Jane | 28 | Aerospace | 8 | Top Secret |
104 | John | 27 | Cyber | 6 | Top Secret |
This query filters the data from the engineers' table based on the condition provided. The clause is used to filter the records. It has three conditions, returned engineers should be under 30 years old (), should have at least 5 years of experience (), and should have a top-secret security clearance (). The operator connects these three conditions, meaning all conditions must be satisfied ('true') for a record to be included in the result. This helps in filtering the exact needed data for the new project.
A foreign key is a column or group of columns in a table that refers to the primary key in another table. The foreign key constraint helps maintain referential integrity between the two tables.
Let's examine employee data from Lockheed Martin's HR database:
:
+------------+------------+------------+------------+ | employee_id| first_name | last_name | manager_id | +------------+------------+------------+------------+ | 1 | Aubrey | Graham | 3 | | 2 | Marshal | Mathers | 3 | | 3 | Dwayne | Carter | 4 | | 4 | Shawn | Carter | | +------------+------------+------------+------------+
In this table, serves as the primary key and functions as a foreign key because it links to the of the employee's manager. This establishes a relationship between Lockheed Martin employees and their managers, allowing for easy querying to find an employee's manager or see which employees report to a specific manager.
The table may also have multiple foreign keys that reference primary keys in other tables. For example, and foreign keys could be used to connect each employee to their respective department and location.
As a data analyst at Lockheed Martin, you have been provided with two tables: and . The table contains information about your clients such as , , , and . The table contains details of each contract implemented by Lockheed Martin, with attributes such as , , , , and .
You are required to find out the total budget for each customer in each industry. Assume that in the table is a foreign key referencing from the table.
customer_id | first_name | last_name | industry |
---|---|---|---|
1 | John | Doe | Aerospace |
2 | Jane | Doe | Defense |
3 | David | Smith | Government |
4 | Olivia | Johnson | Aerospace |
project_id | customer_id | budget | start_date | end_date |
---|---|---|---|---|
101 | 1 | 50000 | 06/01/2022 | 09/01/2022 |
102 | 2 | 80000 | 07/01/2022 | 10/01/2022 |
103 | 1 | 70000 | 06/15/2022 | 09/15/2022 |
104 | 3 | 120000 | 08/01/2022 | 11/01/2022 |
105 | 4 | 110000 | 09/01/2022 | 12/01/2022 |
In the result of this query, each row represents an individual customer with their total budget spent across all projects. The results are grouped by industry and sorted by the total budget in descending order.
Because joins come up so often during SQL interviews, try an interactive Spotify JOIN SQL question:
One way to find duplicatesis to use a clause and then use to find groups
You could also use the operator:
Database normalization is the process of breaking down a table into smaller and more specific tables and defining relationships between them via foreign keys. This minimizes redundancy, and creates a database that's more flexible, scalable, and easier to maintain. It also helps to ensure the integrity of the data by minimizing the risk of data inconsistencies and anomalies.
The best way to prepare for a SQL interview, besides making sure you have strong SQL fundamentals, is to practice a ton of real SQL questions that were asked in recent job interviews. Beyond just solving the above Lockheed Martin SQL interview questions, you should also solve the 200+ SQL questions on DataLemur which come from companies like Microsoft, Google, Amazon, and tech startups.
Each DataLemur SQL question has hints to guide you, detailed solutions and best of all, there is an online SQL coding environment so you can instantly run your query and have it executed.
To prep for the Lockheed Martin SQL interview it is also helpful to practice SQL problems from other defense & aerospace contractors like:
However, if your SQL query skills are weak, forget about jumping right into solving questions – strengthen your SQL foundations with this SQL tutorial for Data Analytics.
This tutorial covers things like GROUP BY and window functions – both of which pop up often during Lockheed Martin interviews.
For the Lockheed Martin Data Science Interview, besides SQL questions, the other types of questions to practice:
To prepare for Lockheed Martin Data Science interviews read the book Ace the Data Science Interview because it's got: