At Tata Elxsi, SQL does the heavy lifting for analyzing data from embedded systems projects, and managing databases for IoT-driven solutions. Unsurprisingly this is why Tata Elxsi almost always evaluates jobseekers on SQL questions during interviews for Data Analytics, Data Science, and Data Engineering jobs.
Thus, to help you ace the Tata Elxsi SQL interview, we've curated 9 Tata Elxsi SQL interview questions – can you answer each one?
Tata Elxsi is a globally renowned technology company. They provide services to diverse industries including automotive, broadcast, healthcare and much more. Consider this situation where Tata Elxsi wants to determine their power customers, i.e., customers who have spent the most on their services over the last year.
The criterion for a power user is a customer who has spent more than $100,000 in the last year.
The customer information is stored in two tables:
customer_id | name | signup_date |
---|---|---|
1 | Anil | 2020-08-12 |
2 | Rahul | 2019-07-15 |
3 | Seema | 2017-06-23 |
4 | Mohit | 2021-03-11 |
order_id | customer_id | service_id | order_price | order_date |
---|---|---|---|---|
A5001 | 1 | S1 | 10000 | 01/05/2022 |
A5002 | 2 | S2 | 20000 | 02/08/2022 |
A5003 | 1 | S3 | 90000 | 03/06/2022 |
A5004 | 2 | S2 | 80000 | 04/11/2022 |
A5005 | 3 | S1 | 50000 | 05/07/2022 |
Create a SQL query that will return a list of power users from the Tata Elxsi customer database.
The output should be:
customer_id | name | total_spent |
---|---|---|
1 | Anil | 100000 |
2 | Rahul | 100000 |
The query to determine the power users from the provided input will be:
This SQL query firstly joins the Customers and Orders tables on the customer_id field to combine these tables into one. Then it filters the orders to those placed in the last year. The SUM aggregate function calculates the total spent by each customer in the last year. The customer_id and name are grouped in the GROUP BY clause to perform the aggregate calculations. The HAVING clause ensures we only see customers who have spent more than $100000 in the last year.
To work on a similar customer analytics SQL question where you can solve it right in the browser and have your SQL query automatically checked, try this Walmart Labs SQL Interview Question:
Sure, here is a SQL Window Function interview question related to Tata Elxsi as per your requirement.
Given the Employee table, write a SQL query to rank the salaries of each employee in each department, and display the department, employee name, salary and rank.
Example Employee Input table:
emp_id | emp_name | department | salary |
---|---|---|---|
1 | Rachel | Marketing | 90000 |
2 | Monica | IT | 60000 |
3 | Ross | Marketing | 120000 |
4 | Chandler | HR | 85000 |
5 | Joey | IT | 75000 |
6 | Phoebe | HR | 80000 |
7 | Gunther | IT | 65000 |
8 | Janice | Marketing | 110000 |
Example Output:
department | emp_name | salary | rank |
---|---|---|---|
HR | Chandler | 85000 | 1 |
HR | Phoebe | 80000 | 2 |
IT | Joey | 75000 | 1 |
IT | Gunther | 65000 | 2 |
IT | Monica | 60000 | 3 |
Marketing | Ross | 120000 | 1 |
Marketing | Janice | 110000 | 2 |
Marketing | Rachel | 90000 | 3 |
The answer uses the RANK() window function in PostgreSQL.
In this solution, we use the RANK() window function to give a unique rank to each row within the department partition, ordered by salary in descending order. The PARTITION BY clause divides the result set into partitions (in this case, each department is a partition). The ORDER BY clause in the OVER clause orders the rows in each partition. The RANK() function then assigns a unique rank to each row within each department. Ranks are given in descending order of salary, so the employee with the highest salary gets the first rank. The final ORDER BY clause orders the result set by department and rank.
To practice a related window function SQL problem on DataLemur's free online SQL coding environment, try this Amazon SQL question asked in a BI Engineer interview:
One way to find duplicate records in a table is by using , and then seeing which groups have more than one occurence:
Another way is by using the operator:
Tata Elxsi, a part of the Tata Group, operates complex services for customers in various sectors including Automotive, Communications, Media & Entertainment and Healthcare. Suppose you are tasked to design a database to manage the service contracts between Tata Elxsi and its customers. The database should keep track of each contract, including details about the customer, the costs associated with the contract and the service provided. Additional details that should be recorded include the start date and end date of the contract, the service category, the account manager responsible for the contract and any specific details or conditions related to the contract.
customer_id | customer_name | sector |
---|---|---|
C101 | Company A | Automotive |
C102 | Company B | Communications |
C103 | Company C | Media & Entertainment |
contract_id | customer_id | start_date | end_date | cost | service_category | account_manager | conditions |
---|---|---|---|---|---|---|---|
CT001 | C101 | 01/01/2022 | 31/12/2022 | 50000 | Design | AM001 | N/A |
CT002 | C102 | 01/04/2022 | 31/03/2023 | 75000 | Testing | AM002 | No overtime |
CT003 | C103 | 01/07/2022 | 30/06/2023 | 60000 | Consultation | AM003 | In-person visits monthly |
Please generate a report showing the total contract cost for each sector for contracts that are currently active.
In this PostgreSQL query, we use a operation to combine the and tables. The clause is used to filter for contracts that are currently active based on their start and end dates. The clause groups the results by sector, and the function aggregates the total cost of contracts for each sector.
{#Question-5}
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.The CHECK constraint is often used in conjunction with other constraints, such as NOT NULL or UNIQUE.
You might consider implementing the CHECK constraint in your database if you want to ensure that certain data meets specific conditions. This can be helpful for maintaining the quality and reliability of your data.
For example, you might use a CHECK constraint to ensure that a column contains only positive numbers, or that a date is within a certain range.
Imagine that you are given the database of all customers of Tata Elxsi, a design company specializing in providing design and technology services for product engineering. The database includes information about the Customer ID, Names, Locations, and the service they acquired. {#Question-6}
Your task is to write the SQL query using the LIKE keyword to filter all the customer records where the service_name starts with 'Design'.
cust_id | cust_name | location | service_name |
---|---|---|---|
101 | John Doe | New York City | Design Service |
102 | Jane Doe | London | Technology Support |
103 | Sam Smith | Los Angeles | Design Technology |
104 | Emma Watson | Berlin | Support Service |
105 | Tom Cruise | Tokyo | Design Support |
cust_id | cust_name | location | service_name |
---|---|---|---|
101 | John Doe | New York City | Design Service |
103 | Sam Smith | Los Angeles | Design Technology |
105 | Tom Cruise | Tokyo | Design Support |
In the above query, we are filtering out the records where the service_name starts with the word 'Design'. The '%' sign after 'Design' is a wildcard in SQL which means it can be followed by any string of characters including no character. Therefore, this would return all service names that start with 'Design'.
A value represents a missing or unknown value. It is different from a zero or a blank space, which are actual values.
It's important to handle values properly in SQL because they can cause unexpected results if not treated correctly. For example, comparisons involving values always result in . Also values are not included in calculations. For example, will ignore values in the column.
Tata Elxsi wants to analyze its customer's orders and returns to understand its product performance. Can you write a SQL query to find out which product category has the most returned orders?
In your query, you should calculate the ratio of orders to orders for each from the customer database (table ) and product details (table ). Please order the result by the in descending order.
Consider the following tables:
order_id | customer_id | product_id | order_date | returned |
---|---|---|---|---|
45123 | 101 | 20001 | 06/20/2020 | 0 |
45124 | 265 | 67532 | 06/22/2020 | 0 |
45125 | 742 | 20001 | 06/25/2020 | 1 |
45126 | 703 | 67532 | 06/28/2020 | 1 |
45127 | 191 | 20001 | 07/15/2020 | 0 |
product_id | product_category |
---|---|
20001 | Electronics |
67532 | Kitchenware |
This query first joins the two tables based on the . Then it counts the number of returned orders (when ) and total orders for each product category using the function. The results are grouped by the . Finally, the calculated ratio is sorted in descending order. The output will show the product category and the corresponding ratio of returned orders to total orders.
Since joins come up so often during SQL interviews, try an interactive SQL join question from Spotify:
At Tata Elxsi, a global design and technology services company, you are given a table of all projects the company has undertaken in the last year. Each project is assigned to an engineer and has a and . Your task is to write a SQL query to find the average duration of projects (in days) for each engineer.
project_id | engineer_id | start_date | end_date |
---|---|---|---|
1 | 101 | 2021-09-01 | 2021-09-05 |
2 | 101 | 2021-09-06 | 2021-09-10 |
3 | 102 | 2021-09-01 | 2021-09-07 |
4 | 102 | 2021-09-08 | 2021-09-15 |
5 | 103 | 2021-09-09 | 2021-09-11 |
engineer_id | average_project_duration |
---|---|
101 | 5 |
102 | 7 |
103 | 3 |
This query works by subtracting the from the for each project, which gives the duration of the project in days. The function is used to extract the number of days from the interval type data. It then calculates the average of these durations, grouped by .
The best way to prepare for a Tata Elxsi SQL interview is to practice, practice, practice. Beyond just solving the earlier Tata Elxsi SQL interview questions, you should also solve the 200+ SQL questions from real Data Science & Analytics interviews which come from companies like Netflix, Airbnb, and Amazon.
Each interview question has hints to guide you, detailed solutions and crucially, there is an online SQL coding environment so you can right in the browser run your SQL query answer and have it graded.
To prep for the Tata Elxsi SQL interview you can also be useful to solve SQL questions from other tech companies like:
In case your SQL skills are weak, forget about diving straight into solving questions – strengthen your SQL foundations with this DataLemur SQL tutorial.
This tutorial covers SQL concepts such as filtering data with WHERE and sorting results with ORDER BY – both of these show up routinely in Tata Elxsi interviews.
In addition to SQL interview questions, the other question categories to practice for the Tata Elxsi Data Science Interview are:
To prepare for Tata Elxsi Data Science interviews read the book Ace the Data Science Interview because it's got: