At General Dynamics, SQL is used quite frequently for analyzing massive defense-related datasets and managing military information systems databases. Unsurprisingly this is why General Dynamics almost always asks SQL problems during interviews for Data Analytics, Data Science, and Data Engineering jobs.
So, if you're preparing for a SQL Assessment, we've collected 7 General Dynamics SQL interview questions to practice, which are simiar to commonly asked questions at General Dynamics – can you solve them?
The fictitious General Dynamics wants to understand who their top customers are based on the purchase frequency. For the context of this question, consider a 'VIP' user as someone who made more than 100 purchases within the last year.
You are given two tables - one is the table, and another is the table. The structure of these tables is outlined below.
user_id | first_name | last_name | signup_date |
---|---|---|---|
1 | John | Doe | 01/07/2021 |
2 | Jane | Smith | 06/15/2021 |
3 | Mike | Johnson | 10/28/2021 |
4 | Emma | Williams | 03/08/2021 |
5 | Ryan | Brown | 12/17/2021 |
purchase_id | user_id | purchase_date | product_id | price |
---|---|---|---|---|
101 | 1 | 03/08/2021 | 20001 | 1000 |
102 | 1 | 05/10/2021 | 30001 | 400 |
103 | 2 | 10/30/2021 | 30001 | 400 |
104 | 1 | 05/05/2021 | 30001 | 400 |
105 | 3 | 12/19/2021 | 20001 | 1000 |
Your task is to write a SQL query to return the first name, last name, and the total number of purchases for all users who made more than 100 purchases in the past year.
This query begins by joining the table to the table on the field. It then filters for purchases made within the last year. It then groups the results by the , , and from the table. Finally, it filters to only show users who have made more than 100 purchases in the past year.
To practice a related customer analytics question on DataLemur's free interactive SQL code editor, try this Microsoft Azure Cloud SQL Interview Question:
You are working as a data analyst in the sales department of General Dynamics. You are given a table containing sales data for various products over multiple months. Your task is to write a SQL query using a window function to calculate the average sales for each product each month.
sale_id | product_id | sale_date | units_sold |
---|---|---|---|
1001 | 101 | 2022-01-01 | 500 |
1002 | 102 | 2022-01-15 | 200 |
1003 | 103 | 2022-01-20 | 700 |
1004 | 101 | 2022-02-01 | 300 |
1005 | 102 | 2022-02-15 | 400 |
1006 | 103 | 2022-02-20 | 600 |
1007 | 101 | 2022-03-01 | 600 |
1008 | 102 | 2022-03-15 | 600 |
1009 | 103 | 2022-03-20 | 800 |
This query extracts the month from the sale_date column and partitions the data by product_id and month. It then calculates the average units sold for each product every month. The ORDER BY clause orders the result by product_id and month.
The result would give the average sales for each product each month. This can be useful to understand the sales performance of each product over time. It can help the company to identify products with consistent high sales or detect any seasonal sales patterns.
To solve a related window function SQL problem on DataLemur's free interactive SQL code editor, try this Amazon SQL question asked in a BI Engineer interview:
Database normalization is a good idea to implement because it can reduce redundancy which can improve performance and database flexibility.
By dividing larger tables into smaller, more modular and specific tables which are linked via foreign keys, this can usually improve the speed of some queries because it minimizes the amount of random data the query has to sift through. However, it's not always 100% true that there is a query speed-up, because joins are an expensive operation.
Nonetheless, by reducing redundancy, besides improved performance you also get more database flexibility. By making tables more modular and reducing overlap, you're able to more easily, since one table can be changed more effortlessly without affecting others. This makes it easier to adapt the database schema to General Dynamics's evolving business needs.
General Dynamics is a major contractor for the Department of Defense. As such, it is critical to understand the average duration of these contracts in order to plan resources efficiently. Given a table of DoD contracts with its start and end dates, calculate the average duration of contracts for each year.
contract_id | start_date | end_date |
---|---|---|
001 | 2018-01-01 | 2018-12-31 |
002 | 2018-02-12 | 2019-02-11 |
003 | 2019-01-01 | 2020-12-31 |
004 | 2020-01-11 | 2021-01-10 |
005 | 2020-03-01 | 2022-03-31 |
year | avg_duration_days |
---|---|
2018 | 330.5 |
2019 | 365 |
2020 | 396 |
In the SQL query above, we are grouping by the years of the contract starting date and calculating the average difference between the end and start dates of contracts. The DATEDIFF function used in SQL returns the difference in days between two dates, thus providing the contract duration. This result gives us the average contract duration for each year. Please note the output might vary slightly depending on the date values used in the example.
A DBMS (database management system), in order to ensure transactions are relaible and don't ruin the integrity of the data, tries to mantain the following ACID properties: Atomicity, Consistency, Isolation, and Durability.
To make this concept more concrete, here is what each of the ACID properties would mean in the context of banking transactions:
We want to find the average product review stars every month. We are given a table with fields , , , , and . The indicate the rating of a particular product by a user, and the holds the date of the review submission.
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 |
Here is the SQL query to derive the required data:
Expected output:
mth | product | avg_stars |
---|---|---|
6 | 50001 | 3.50 |
6 | 69852 | 4.00 |
7 | 69852 | 2.50 |
This query first extracts the month from the field and groups the reviews by this extracted month and . It then calculates the average star rating for each group.
A cross-join, also known as a cartesian join, is a type of JOIN operation in SQL that creates a new table by combining each row from the first table with every row from the second table. This results in a table with a row for every possible combination of rows from the two input tables.
An example of when this might be useful is if you wanted to first make a dataset containing all possible pairs of customers and products data, in order to later build a Machine Learning model to predict the probability of a customer purchasing a particular product.
However, it is important to note that cross-joins can create very large tables, especially if the input tables have a large number of rows. For example, if you had 10,000 customers and 5,000 different product SKUs, the resulting cross-join would have 50 million rows.
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. In addition to solving the earlier General Dynamics SQL interview questions, you should also solve the 200+ SQL questions from real Data Science & Analytics interviews which come from companies like Facebook, Google, and VC-backed startups.
Each interview question has multiple hints, 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 checked.
To prep for the General Dynamics SQL interview it is also a great idea to practice SQL questions from other defense & aerospace contractors like:
However, if your SQL query skills are weak, don't worry about jumping right into solving questions – strengthen your SQL foundations with this SQL interview tutorial.
This tutorial covers things like math functions and Self-Joins – both of these show up frequently during General Dynamics SQL interviews.
For the General Dynamics Data Science Interview, beyond writing SQL queries, the other types of questions to prepare for are:
The best way to prepare for General Dynamics Data Science interviews is by reading Ace the Data Science Interview. The book's got: