Nasdaq employees use SQL often for analyzing stock market data patterns and managing databases for financial reporting. Because of this, Nasdaq covers SQL questions in interviews for Data Science and Data Engineering positions.
Thus, to help you prepare, we've collected 11 Nasdaq SQL interview questions – able to answer them all?
Let's imagine, that as a data analyst at Nasdaq, you have been asked to analyze trading volume trends for a specific stock. Create a SQL query that can be used to calculate the average daily trading volume for a specific stock over the last three months, compared with the same period the previous year.
Here's a hypothetical table of daily trading volumes per stock:
trade_date | stock_symbol | volume |
---|---|---|
2022-09-02 | AAPL | 1,030,992 |
2022-09-02 | MSFT | 1,095,235 |
2022-09-01 | AAPL | 1,070,760 |
2022-09-01 | MSFT | 1,120,193 |
2021-09-02 | AAPL | 1,101,234 |
2021-09-02 | MSFT | 1,130,042 |
2021-09-01 | AAPL | 1,098,723 |
2021-09-01 | MSFT | 1,145,889 |
We want to know, for example, the average daily volume for the stock symbol AAPL over the last three months (June 01, 2022 - August 31, 2022), compared with the same period (June 01, 2021 - August 31, 2021) the previous year.
This query uses window function to calculate the average daily trading volume for the given period, and then compares it with the average daily trading volume for the same period from the previous year for the specified stock.
For more window function practice, try this Uber SQL Interview Question on DataLemur's interactive SQL code editor:
Given a table of Nasdaq employee salaries, write a SQL query to find the top 3 highest earning employees within each department.
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_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 |
Solve this problem 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.
If the solution above is tough, you can find a detailed solution with hints here: Top 3 Department Salaries.
Stay up to date and read up on recent news and insights from Nasdaq!
Views are a lot like virtual tables, where you can take a base table and customize it (such as by hiding some data from non-admin users, or removing some random columns/rows based on business requirements).
Here's the PostgreSQL syntax for creating a view based on data in the table:
You work as a part of the analytics team at Nasdaq. You are given access to the two databases - 'traders' and 'trades'. The 'traders' database contains the detail of each trader along with their registration date and the 'trades' database contains the record for each deal made by traders. Your task is to write a SQL query that filters out traders who registered after '01/01/2020' and made more than 10 trades in the 'Technology' sector.
trader_id | register_date |
---|---|
317 | 02/01/2020 |
502 | 03/05/2020 |
293 | 06/18/2019 |
352 | 09/01/2021 |
481 | 08/05/2018 |
trade_id | trader_id | trade_date | quantity | sector |
---|---|---|---|---|
6171 | 317 | 04/08/2020 | 1000 | 'Technology' |
7802 | 502 | 06/10/2020 | 200 | 'Healthcare' |
5293 | 293 | 07/18/2020 | 300 | 'Technology' |
6352 | 352 | 10/26/2021 | 500 | 'Technology' |
4517 | 481 | 11/05/2021 | 750 | 'Technology' |
This query first identifies all trades that were made in the 'Technology' sector and counts the number of trades for each trader. This is done in the subquery . This subquery is then joined to the table using a JOIN clause. Finally, this query filters down the result to only contain traders who registered after '01/01/2020' and made more than 10 trades in the 'Technology' sector.
The / operator is used to remove to return all rows from the first SELECT statement that are not returned by the second SELECT statement.
Note that is available in PostgreSQL and SQL Server, while MINUS is available in MySQL and Oracle (but don't stress about knowing which DBMS supports what exact commands since the interviewers at Nasdaq should be lenient!).
Here's a PostgreSQL example of using EXCEPT to find all of Nasdaq'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 EXCEPT ALL operator instead of EXCEPT. The EXCEPT ALL operator will return all rows, including duplicates.
As a Financial Analyst at Nasdaq, you are interested in understanding the average daily trading volume for different stocks. Trading volume represents the total number of stocks traded for a specified company. Write a SQL query to find the average daily trading volumes for each stock listed in Nasdaq for the month of May 2022.
date | ticker | volume |
---|---|---|
05/01/2022 | AAPL | 123456789 |
05/01/2022 | MSFT | 987654321 |
05/02/2022 | AAPL | 234567890 |
05/02/2022 | MSFT | 876543210 |
05/03/2022 | AAPL | 345678901 |
05/03/2022 | MSFT | 765432109 |
05/04/2022 | AAPL | 456789012 |
05/04/2022 | MSFT | 654321098 |
05/05/2022 | AAPL | 567890123 |
05/05/2022 | MSFT | 543210987 |
ticker | avg_volume_may_2022 |
---|---|
AAPL | 345678543 |
MSFT | 765432305 |
The above SQL statement groups the trading volume data for each stock(ticker) and calculates their average for the month of May 2022. The WHERE clause is used to filter the data for the month of May 2022. The AVG function is used to calculate the average trading volume for each stock.
The two most similar questions could be:
However, the final markdown would be generated as follows:
To practice a very similar question try this interactive Robinhood Cities With Completed Trades Question which is similar for involving trading-related data and aggregation or this Amazon Highest-Grossing Items Question which is similar for involving average calculations on financial data.
A self-join is a type of JOIN where a table is joined to itself. To execute a self-join, you must include the table name twice in the FROM clause and assign a different alias to each instance. You can then join the two copies of the table using a JOIN clause, and use a WHERE clause to specify the relationship between the rows.
For instance, suppose you had website visitor data for Nasdaq, exported from the company's Google Analytics account. To assist the web-dev team, you needed to analyze pairs of pages for UX or navigational issues. As part of that analysis, you wanted to generate all pairs of URLs, but needed to exclude pairs where both URLs were the same since that is not a valid pair."
You could use the following self-join:
This query returns the url of each page () along with the url of the page that referred to it (). The self-join is performed using the field, which specifies the id of the page that referred the visitor to the current page, and avoids any pages that referred themself (aka data anomalies).
Imagine you're working for Nasdaq and are tasked with tracking the average daily trading volume for each stock on a monthly basis.
trade_id | trade_date | stock_symbol | trade_volume |
---|---|---|---|
1001 | 2022-06-01 | AAPL | 1000 |
1002 | 2022-06-03 | AAPL | 2000 |
1003 | 2022-06-15 | TSLA | 4000 |
1004 | 2022-07-02 | GOOGL | 6000 |
1005 | 2022-07-15 | TSLA | 3000 |
1006 | 2022-07-19 | AAPL | 2500 |
1007 | 2022-07-25 | GOOGL | 7000 |
month | stock_symbol | avg_daily_trade_volume |
---|---|---|
6 | AAPL | 1500.00 |
6 | TSLA | 4000.00 |
7 | AAPL | 2500.00 |
7 | GOOGL | 6500.00 |
7 | TSLA | 3000.00 |
This query first extracts the month from the trade date, then groups by both the extracted month and the stock symbol. It calculates the average daily trade volume for each stock by month. The output is ordered by month and stock symbol.
You have a database that contains a list of companies listed in Nasdaq exchange. The table consists of the columns , , , and . Write an SQL query that retrieves all companies which have "TECH" in their names.
company_id | company_name | listing_date | sector | CEO_name |
---|---|---|---|---|
1 | 'APPLE INC' | '12/12/1980' | 'TECHNOLOGY' | 'Tim Cook' |
2 | 'AMAZON.COM INC' | '05/15/1997' | 'CONSUMER DISCRETIONARY' | 'Andy Jassy' |
3 | 'MICROSOFT CORP' | '03/13/1986' | 'TECHNOLOGY' | 'Satya Nadella' |
4 | 'ALPHABET INC' | '08/19/2004' | 'COMMUNICATION SERVICES' | 'Sundar Pichai' |
5 | 'FACEBOOK INC' | '05/18/2012' | 'COMMUNICATION SERVICES' | 'Mark Zuckerberg' |
6 | 'TECHTRONICS INDUSTRIES' | '09/15/2008' | 'INDUSTRIALS' | 'Joseph Galli Jr.' |
7 | 'TECH DATA CORP' | '11/02/1984' | 'TECHNOLOGY' | 'Rich Hume' |
This query uses the keyword in SQL which allows us to match text string patterns. In this case, we are retrieving all records from table where the company's name contains the string 'TECH'. The '%' sign is a wild card that matches any number of characters.
The CHECK constraint is used to enforce rules on the data in a specific column. If a row is inserted or updated with data that does not follow the CHECK constraint's rule, the operation will fail.
For example, say you had a marketing analytics database that stores ad campaign data from Nasdaq's Google Analytics account.
Here's what some constraints could look like:
The CHECK constraint is used in the above example to make sure that the "budget" and "cost_per_click" fields contain only positive values. This helps to maintain the validity and integrity of the data in the context of ad campaigns.
The CHECK constraint can also be used to enforce other specific conditions on data. For example, you can use it to ensure that the "start_date" for each ad campaign is earlier than the "end_date."
For the company Nasdaq, you have been given two tables - 'customers' and 'trades'.
The 'customers' table has a unique id for each customer, along with additional information such as the customer's name and country.
The 'trades' table has a record of all trades done by customers, including the id of the customer who did the trade, the stock symbol, the trade amount and the trade date.
Write a SQL query to find out the total trade amount for each stock symbol for customers from the United States in the year 2021.
customer_id | name | country |
---|---|---|
1 | John Doe | United States |
2 | Jane Smith | United Kingdom |
3 | Alice Johnson | United States |
trade_id | customer_id | stock_symbol | trade_amount | trade_date |
---|---|---|---|---|
101 | 1 | AAPL | 2000 | 2021-06-15 |
102 | 2 | AAPL | 1500 | 2021-07-20 |
103 | 1 | GOOGL | 3000 | 2021-06-25 |
104 | 3 | AAPL | 2500 | 2021-09-30 |
This query first joins the 'trades' table with the 'customers' table on the . It then applies a filter to restrict the records to only those where the customer's country is 'United States' and the trade date is in the year 2021. It finally performs a group by operation on the and calculates the total trade amount for each stock symbol.
Since join questions come up frequently during SQL interviews, try this SQL join question from Spotify:
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. Besides solving the above Nasdaq SQL interview questions, you should also solve the 200+ FAANG SQL Questions on DataLemur which come from companies like Google, Facebook, Microsoft and Amazon.
Each DataLemur SQL question has hints to guide you, fully explained answers along with a discussion board to see how others solved it and best of all, there is an interactive coding environment so you can instantly run your SQL query answer and have it graded.
To prep for the Nasdaq SQL interview it is also helpful to practice SQL questions from other stock exchange & brokerage companies like:
In case your SQL coding skills are weak, don't worry about diving straight into solving questions – improve your SQL foundations with this SQL tutorial for Data Analytics.
This tutorial covers SQL concepts such as filtering data with WHERE and turning a subquery into a CTE – both of which show up often during SQL job interviews at Nasdaq.
In addition to SQL interview questions, the other topics covered in the Nasdaq Data Science Interview are:
To prepare for Nasdaq Data Science interviews read the book Ace the Data Science Interview because it's got: