Oracle loves databases so much they invented their own SQL flavor, Oracle SQL. So it shouldn't surprise you that Oracle frequently asks SQL coding questions during interviews for Data Analyst, Data Science, and BI jobs. While for some speciality positions you must answer in the Oracle SQL dialect, often for more general Data roles it's okay to use MySQL or PostgreSQL too.
To prepare for the Oracle SQL Assessment, we've curated 10 Oracle SQL interview questions to practice, which are similar to commonly asked questions at Oracle – how many can you solve?
As a data analyst on the Oracle Sales Operations team, you are given a list of salespeople’s deals, and the annual quota they need to hit.
Write a query that outputs each employee id and whether they hit the quota or not ('yes' or 'no'). Order the results by employee id in ascending order.
Definitions:
Column Name | Type |
---|---|
employee_id | integer |
deal_size | integer |
employee_id | deal_size |
---|---|
101 | 400000 |
101 | 300000 |
201 | 500000 |
301 | 500000 |
Column Name | Type |
---|---|
employee_id | integer |
quota | integer |
employee_id | quota |
---|---|
101 | 500000 |
201 | 400000 |
301 | 600000 |
employee_id | made_quota |
---|---|
101 | yes |
201 | yes |
301 | no |
So see step by step instruction on how to get to this answer try this question for FREE on our interactive coding site, Oracle SQL Interview Question.
As the Sales Operations Analyst at Oracle, you have been tasked with assisting the VP of Sales in determining the final compensation earned by each salesperson for the year. The compensation structure includes a fixed base salary, a commission based on total deals, and potential accelerators for exceeding their quota.
Each salesperson earns a fixed base salary and a percentage of commission on their total deals. Also, if they beat their quota, any sales after that receive an accelerator, which is just a higher commission rate applied to their commissions after they hit the quota.
Write a query that calculates the total compensation earned by each salesperson. The output should include the employee ID and their corresponding total compensation, sorted in descending order. In the case of ties, the employee IDs should be sorted in ascending order.
Column Name | Type |
---|---|
employee_id | integer |
base | integer |
commission | double |
quota | integer |
accelerator | double |
employee_id | base | commission | quota | accelerator |
---|---|---|---|---|
101 | 60000 | 0.1 | 500000 | 1.5 |
102 | 50000 | 0.1 | 400000 | 1.5 |
Column Name | Type |
---|---|
employee_id | integer |
deal_size | integer |
employee_id | deal_size |
---|---|
101 | 400000 |
101 | 400000 |
102 | 100000 |
102 | 200000 |
employee_id | total_compensation |
---|---|
101 | 155000 |
102 | 80000 |
Here is a simple database schema and SQL query for this scenario:
Try this Oracle SQL Interview Question on DataLemur to get access to hints and additional solutions!
Normalizing a database involves dividing a large table into smaller and more specialized ones, and establishing relationships between them using foreign keys. This reduces repetition, resulting in a database that is more adaptable, scalable, and easy to maintain. Additionally, it helps to preserve the accuracy of the data by reducing the likelihood of inconsistencies and problems.
Oracle is focusing on improving its digital marketing and sales strategy. You have a database that contains two tables: one for Clicks on digital ads (Table ) and one for Products added to the cart (Table ).
The table shows every click on a digital ad for a product, capturing the product_id and user_id. The table shows every time a product is added to the cart, also capturing the product_id and user_id.
Calculate the click-through conversion rate for each product_id, defined as the number of times the product was added to the cart divided by the number of clicks on the product's ads.
click_id | user_id | click_date | product_id |
---|---|---|---|
1023 | 534 | 06/09/2022 09:03:00 | 20010 |
2019 | 299 | 06/10/2022 13:37:00 | 20011 |
3035 | 467 | 06/11/2022 16:54:00 | 20010 |
4092 | 123 | 07/15/2022 11:00:00 | 20011 |
5011 | 867 | 07/20/2022 09:20:00 | 20010 |
cart_id | user_id | add_to_cart_date | product_id |
---|---|---|---|
1523 | 534 | 06/09/2022 09:15:00 | 20010 |
2541 | 123 | 06/10/2022 13:49:00 | 20011 |
3570 | 467 | 06/11/2022 17:00:00 | 20010 |
4562 | 123 | 07/15/2022 12:00:00 | 20011 |
5502 | 458 | 07/20/2022 10:00:00 | 20011 |
This SQL statement gets the conversion rate for each product_id. The conversion rate is calculated by dividing the number of times the product was added to the cart (from ) by the number of clicks on the product's ad (from ). The left join on and is to ensure that we count only the instances where the user who clicked the ad is the one who added the item to the cart.
To solve a similar problem about calculating rates, try this TikTok SQL question on DataLemur's interactive SQL code editor:
Some similarities between unique and non-unique indexes include:
Some differences between unique and non-unique indexes include:
To solve a similar problem about calculating rates, try this TikTok SQL question on DataLemur's interactive SQL code editor:
As a tech company, Oracle offers a diverse range of products including databases, cloud solutions, and other software services. The company would likely be interested in understanding the average sales revenue by product category.
The marketing team at Oracle wants to understand the average sales revenue made for each product category each month. Given a relational table called 'sales' with columns (unique identifier for the sale), (unique identifier for the product), (unique identifier for product category), (date of the sale), and (revenue from sale), write an SQL query that retrieves the average revenue per product category for each month.
sales_id | product_id | category_id | sales_date | revenue |
---|---|---|---|---|
1001 | 5001 | 1 | 06/18/2022 | 3500 |
1002 | 6985 | 2 | 06/18/2022 | 4700 |
1003 | 5001 | 1 | 07/27/2022 | 3700 |
1004 | 6985 | 2 | 08/25/2022 | 5000 |
1005 | 5000 | 1 | 06/18/2022 | 3000 |
month | category | avg_revenue |
---|---|---|
6 | 1 | 3250 |
6 | 2 | 4700 |
7 | 1 | 3700 |
8 | 2 | 5000 |
This query first extracts the month from the column, then groups the data by this month and the product category . The function is used to calculate the average revenue in each group, and the result is ordered by month and category for easy readability.
A correlated sub-query is a sub-query that depends on the outer query and cannot be executed separately. It uses the outer query to filter or transform data by referencing a column from it, and the outer query uses the results of the inner query. In contrast, a non-correlated sub-query is independent of the outer query and can be executed on its own. It does not reference any columns from the outer query and is used to retrieve additional data needed by the outer query.
Here is an example of a correlated sub-query:
This query selects the and total sales of all Oracle customers in the sales table whose are greater than the average of their own customer group. The sub-query in this case is correlated with the outer query, as it references the column from the outer query ().
Here is an example of a non-correlated sub-query:
The sub-query in this case is non-correlated, as it does not reference any columns from the outer query.
Performance-wise, correlated sub-queries are generally slower to execute, as they have to be re-evaluated for each row of the outer query, while non-correlated sub-queries are faster, as they only have to be executed once.
You are the Database Administrator for Oracle. The company maintains a database of its customers. The database has a table with details such as , , , and .
Your task is to create a SQL query that will filter down the records of customers who are from any company that has the string 'Oracle' in its name (it could be Upper Case or Lower Case or a mix of both).
customer_id | first_name | last_name | email_id | company_name |
---|---|---|---|---|
001 | John | Doe | john.doe@example.com | Oracle |
002 | Jane | Smith | jane.smith@example.com | Microsoft |
003 | Mary | Johnson | mary.johnson@example.com | Oracle Solutions |
004 | James | Brown | james.brown@example.com | |
005 | Patricia | Miller | patricia.miller@example.com | Oracle Cloud |
customer_id | first_name | last_name | email_id | company_name |
---|---|---|---|---|
001 | John | Doe | john.doe@example.com | Oracle |
003 | Mary | Johnson | mary.johnson@example.com | Oracle Solutions |
005 | Patricia | Miller | patricia.miller@example.com | Oracle Cloud |
This SQL query uses the LIKE keyword with the % wildcard to match any company name that has the string 'Oracle' anywhere in its name. The LOWER function is used to convert the company names to lower case, ensuring the case-insensitive search.
A common analysis is to calculate the average purchase amount by age groups. Use the and tables.
The table has such columns: , , ,
The table includes , , , , .
We want to join these tables based on customer_id, calculate the age of customers, group them into age bins, and calculate the average purchase amount for each age group.
customer_id | first_name | last_name | birthdate |
---|---|---|---|
1001 | John | Doe | 1980-05-01 |
1002 | Jane | Smith | 1990-10-30 |
1003 | Jim | Brown | 2000-01-20 |
1004 | Jill | Jones | 1965-07-05 |
1005 | Bob | Johnson | 1975-12-15 |
purchase_id | customer_id | purchase_date | product_id | amount |
---|---|---|---|---|
8223 | 1001 | 2022-07-10 | 70001 | 200.00 |
8315 | 1002 | 2022-08-05 | 80052 | 150.00 |
8236 | 1003 | 2022-06-18 | 70009 | 220.00 |
8252 | 1004 | 2022-05-15 | 80952 | 180.00 |
8301 | 1005 | 2022-11-05 | 80882 | 250.00 |
This SQL query begins by joining the and tables based on customer_id. Then, it calculates the age of customers at the time of purchase and categorizes customers into age groups: '0-30', '30-50', and '> 50'. Finally, the query calculates the average purchase amount for each age group.
Because joins come up so often during SQL interviews, try an interactive Spotify JOIN SQL question:
To find records in one table that aren't in another, you can use a and check for values in the right-side table.
Here is an example using two tables, Oracle employees and Oracle managers:
This will return all rows from Oracle employees where there is no matching row in managers based on the column.
You can also use the operator in PostgreSQL and Microsoft SQL Server to return the records that are in the first table but not in the second. Here is an example:
This will retrieve all rows from employees that do not appear in managers. The operator works by retreivingthe rows that are returned by the first query, but not by the second.
Please note that is not supported by all DBMS systems, such as MySQL and Oracle (however, you can use the operator to achieve a similar outcome).
Because joins come up so often during SQL interviews, try an interactive Spotify JOIN SQL question:
The best way to prepare for a Oracle SQL interview is to practice, practice, practice. Beyond just solving the above Oracle SQL interview questions, you should also solve the 200+ DataLemur SQL Interview Questions which come from companies like FAANG and tech startups.
Each DataLemur SQL question has multiple hints, step-by-step solutions and crucially, there is an interactive SQL code editor so you can right in the browser run your SQL query and have it checked.
To prep for the Oracle SQL interview it is also a great idea to solve SQL problems from other tech companies like:
However, if your SQL foundations are weak, forget about diving straight into solving questions – go learn SQL with this SQL tutorial for Data Analytics.
This tutorial covers SQL concepts such as aggregate functions and rank window functions – both of which pop up often in SQL job interviews at Oracle.
For the Oracle Data Science Interview, in addition to SQL query questions, the other types of questions which are covered:
To prepare for Oracle Data Science interviews read the book Ace the Data Science Interview because it's got: