# 11 TANLA SQL Interview Questions (Updated 2024)

Updated on

June 23, 2024

Data Analysts and Data Engineers at TANLA write SQL queries almost every single workday. They use SQL for analyzing customer interaction data for optimization and deriving insights from communication trends for business strategy formulation. That's the reason behind why TANLA frequently asks jobseekers SQL coding interview questions.

Thus, to help you prep, here’s 11 TANLA SQL interview questions – able to answer them all?

## 11 TANLA SQL Interview Questions

### SQL Question 1: Identify Power Users at TANLA

The TANLA company has a database containing information about the number of services each customer subscribes to every month. Your task is to write a SQL query to identify power users who subscribe to the services more frequently. A "power user" is defined as a user who subscribes to at least 10 services in a month.

Here are some sample data:

##### Example Input:
subscription_iduser_idsubscription_dateservice_id
1023106/08/2022501
2011206/09/2022502
3281106/18/2022503
2012207/26/2022502
1024107/5/2022501
1025107/10/2022501
2013207/15/2022502
1026107/20/2022501
1027107/25/2022501
3282107/30/2022503
2014207/31/2022502

This query groups the records by user and the month of subscription. The 'HAVING' clause filters out any user who subscribes to fewer than 10 services in a month. The result is then ordered in descending order of the number of subscriptions.

To practice another SQL customer analytics question where you can solve it interactively and have your SQL solution automatically checked, try this Walmart Labs SQL Interview Question:

### SQL Question 2: Department vs. Company Salary

You're given a table of TANLA employee and department salaries. Write a SQL query to find departments where the departments average salary is higher than the company's average salary.

Code your solution to this question interactively on DataLemur:

The solution is LONG – 30+ lines of SQL. You can find a step-by-step solution here: Department Salaries.

### SQL Question 3: Can you explain the purpose of the constraint and give an example of when you might use it?

The CHECK constraint is used to set a rule for the data in a column. If a row is inserted or updated and the data in the column does not follow the rule specified by the CHECK constraint, the operation will be unsuccessful.

For example, say you had TANLA customer data. You could use a CHECK constraint to ensure that the email column contains only properly formatted email addresses, or that the age column contains only positive integer. Here's an example of that:

### SQL Question 4: Ranking Accounts By Revenue Over Time

In TANLA, there is a need to track and display which accounts are generating the most revenue over time, to incentivize top performers.

The business analytics team wants you to write a SQL query that will list all accounts, their total revenue per year, and a ranking of each account by revenue per year.

There will be two tables "Accounts" and "Transactions". The "Accounts" table will list all the accounts with their account_id. The "Transactions" table will track all transactions by "account_id", showing the revenue generated, and the date the revenue was realized.

The output of your query should be:

• Year
• Account ID
• Total Revenue that year
• Their rank that year based on the total revenue
account_id
100
200
300
##### Example Input:
transaction_idaccount_idamounttransaction_date
110010002020-01-01
210020002020-06-01
320030002020-07-01
420040002020-11-01
530050002021-01-01
630060002021-06-01
720070002021-07-01
810080002021-11-01

This query will first group the transactions by their account_id and the year the transaction was made. It will then sum up the total revenue for each group.

The window function is then used to rank these groups within their years, ordered by the descending total revenue. In PostgreSQL, the EXTRACT function is used to get the year from the date.

The result will be a list of each account, along with the total revenue they made each year and their rank that year. The results are then sorted by Year and Revenue Rank.

p.s. Window functions show up super often during SQL interviews, so practice the 27+ window function questions on DataLemur

### SQL Question 5: How do relational and non-relational databases differ?

While both types of databases are used to store data (no duh!), relational databases and non-relational (also known as NoSQL databases) differ in a few important ways, most importantly on the way data is stored. Relational databases use a data model consisting of tables and rows, while NoSQL databases use a variety of data models, including document, key-value, columnar, and graph storage formats.

This added flexibilty makes NoSQL databases great for non-tabular data (like hierarchal data or JSON data), or data where the type/format is constantly evolving. With this added flexibility, comes one big weakness – you won't get ACID-compliance. That means, unlike relational databases which are typically adhere to the ACID properties (atomic, consistent, isolated, and durable), you don't get as strong guarentees with most non-relational databases.

### SQL Question 6: Filter Customer Database For Latest Transactions

You work at TANLA, a leading cloud communication provider. Your task is to write an SQL query to filter the customer transaction database for every customer’s latest transaction. Assume the date of the transactions is in the format 'YYYY-MM-DD'.

Sample 'transactions' table:

transaction_idcustomer_idtransaction_dateproduct_idamount
15016542022-06-0161001200
23027892022-07-0571052300
12934562022-06-1161001150
27521232022-07-1571052120
45176542022-07-0271052280

Your SQL query should return a table in the below format:

customer_idlatest_transactionproduct_idamount
6542022-07-0271052280
7892022-07-0571052300
4562022-06-1161001150
1232022-07-1571052120

This SQL query will first group the transactions table by customer ID and pick out the most recent transaction date for each customer (subquery b). It then joins this subquery back onto the original transactions table on both customer ID and transaction date, effectively filtering for each customer's most recent transaction only.

### SQL Question 7: Could you clarify the difference between a left and a right join?

In SQL, both a left and right join is used to combine rows from different tables based on a shared key or set of keys, resulting in a single merged table of data. However, here's the difference:

LEFT (OUTER) JOIN: Retrieves all the records/rows from the left and the matched records/rows from the right table.

RIGHT (OUTER) JOIN: Retrieves all the records/rows from the right and the matched records/rows from the left table.

### SQL Question 8: Average Time to Resolve a Claim

In Tanla, a cloud communications company, they handle a number of customer claims on a daily basis. You are given a table recording customer , , , etc. Please compute the average time to resolve a claim for every month. The result has to include , and in days. If a claim is not yet resolved, exclude it from the result.

Example Input:

claim_iduser_idsubmit_dateresolved_date
101205/05/2022 00:00:0005/07/2022 14:00:00
102405/15/2022 10:00:0005/15/2022 16:00:00
103206/07/2022 14:00:0006/10/2022 11:00:00
104307/01/2022 09:30:00
105407/18/2022 13:00:0007/19/2022 10:00:00

Example Output:

MonthUserAverage_time_to_resolve_claim (days)
522.58
540.25
622.88
740.87

In this query, function is used to get the month part of the datetime. The function is used to get the average of time differences between submit_date and resolved_date. The difference is translated into days by dividing by 86400 (number of seconds in a day). The clause ensures that only resolved claims are considered. The result is grouped by Month and User.

The two most similar questions are:

1. "Average Review Ratings" - This problem from Amazon is about retrieving average metrics (review ratings) for each product for every month. Like the Tanla question, this requires averaging and date manipulations.

2. "User's Third Transaction" - This Uber problem involves filtering data based on a condition (third ride). It is similar to the Tanla problem, where we need to filter out unresolved claims.

So the markdown-friendly output is:

To practice a very similar question try this interactive Amazon Average Review Ratings Question which is similar for averaging and date manipulations or this Uber User's Third Transaction Question which is similar for filtering data based on a condition.

### SQL Question 9: Calculate the Click Through Rate (CTR) for Ads

Tanla Solutions, a cloud communications company, is interested in understanding their ad campaign performance through a metric known as Click Through Rate (CTR). They define CTR as the number of clicks an ad receives divided by the number of times the ad is shown (impressions) expressed as a percentage. Given two tables and , can you write a SQL query to calculate the CTR for each ?

##### Example Input:
110006/08/2022 00:00:00
210106/10/2022 00:00:00
310006/18/2022 00:00:00
410207/26/2022 00:00:00
510107/05/2022 00:00:00
##### Example Input:
110006/09/2022 00:00:00
210106/10/2022 00:00:00
310106/15/2022 00:00:00
410007/28/2022 00:00:00
510207/05/2022 00:00:00

This query first joins the table with the table on . It then groups by and for each , it computes the CTR as the number of clicks divided by the number of impressions multiplied by 100 to convert it to a percentage. Because we've used a LEFT JOIN, ads that have impressions but no clicks will still be included in the result with a CTR of 0.

To practice a related SQL problem on DataLemur's free interactive coding environment, attempt this SQL interview question asked by Facebook:

### SQL Question 10: What does database normalization mean?

To normalize a database, tables are divided into smaller, more specialized ones and relationships between them are defined via primary and foreign keys. This minimizes redundancy, making the database more flexible, scalable, and easier to maintain. Normalization also helps to ensure the accuracy of the data by reducing the likelihood of inconsistencies and errors.

### SQL Question 11: Join and Analyze Customer and Product Data

You are given two tables, and , that contain information about customers' purchases at TANLA. The table has columns , , , , and . The table has columns , , , and .

A third table, , links the and table together. It has columns , , and . Write a SQL query to find the total spending of each customer.

##### table:
cust_idnamegenderDOBlocation
1John DoeMale12/12/1990New York
2Jane DoeFemale07/25/1985Los Angeles
3Mike ChanMale05/22/1988Chicago
##### table:
prod_idprod_namecategoryprice
101iPhoneElectronics999.99
102MacBookElectronics1299.99
103T-ShirtApparel19.99
##### table:
cust_idprod_idpurchase_date
110102/23/2022
110302/23/2022
210103/05/2022
310201/25/2022
310302/22/2022

This SQL command is using two JOINS to link the , and tables. It's then finding the sum (total) of the prices of the products associated with each customer in the and table, hence indicating total customer spending.

Because join questions come up routinely during SQL interviews, take a stab at this interactive Snapchat SQL Interview question using JOINS:

### TANLA SQL Interview Tips

The best way to prepare for a TANLA SQL interview is to practice, practice, practice. In addition to solving the above TANLA SQL interview questions, you should also solve the 200+ FAANG SQL Questions on DataLemur which come from companies like Facebook, Google and unicorn tech startups.

Each interview question has multiple hints, step-by-step solutions and crucially, there's an interactive coding environment so you can right in the browser run your query and have it checked.

To prep for the TANLA SQL interview you can also be wise to solve SQL problems from other tech companies like:

But if your SQL coding skills are weak, don't worry about going right into solving questions – strengthen your SQL foundations with this DataLemur SQL Tutorial.

This tutorial covers things like LEAD/LAG window functions and handling date/timestamp data – both of these show up frequently in SQL job interviews at TANLA.

### TANLA Data Science Interview Tips

#### What Do TANLA Data Science Interviews Cover?

In addition to SQL interview questions, the other question categories tested in the TANLA Data Science Interview are:

• Probability & Statistics Questions
• Python Pandas or R Coding Questions
• Data Case Study Questions
• ML Modelling Questions
• Behavioral & Resume-Based Questions

#### How To Prepare for TANLA Data Science Interviews?

I'm sorta biased, but I believe the best way to study for TANLA Data Science interviews is to read my book Ace the Data Science Interview.

The book solves 201 interview questions sourced from Google, Microsoft & tech startups. It also has a refresher covering SQL, Product-Sense & ML. And finally it's helped thousands of people land their dream job in data, which is why it's got over 1000+ 5-star reviews on Amazon.