Swiggy (BA) - Technical Interview (
Swiggy (BA) - Technical Interview (
Time- 1.5 hr
-----------------------------------------------------------------------------------
------------------------------------------------------------
Question 2:
Given two tables, Table-A and Table-B, with the following data:
Table-A | Table-B
---------------------
1 | 1
1 | 2
NULL | NULL
Inner Join- 2
Right Join - 2*1 + 2 = 4
Left Join - 2*1 + 1 = 3
Full Outer Join - 2*1 + 1 + 2 = 5
inner join :
1 1
1 1
right join:
1 1
1 1
null 2
null null
left join:
1 1
1 1
null null
1 1
1 1
null 2
null null
null null
-----------------------------------------------------------------------------------
---------------------------------------------------------------
Question 3:
Find the second-highest salary from an employee table using at least three
different approaches.
Compare using a subquery in the WHERE clause versus using LIMIT and OFFSET.
Discuss which approach is more optimized and why.
limit n-1, 1
select salary
from emp
order by salary desc
limit 1,1
SELECT salary
FROM (
SELECT salary, RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees
) ranked_salaries
WHERE salary_rank = 2; // this can be done using cte too
select salary
from emp
where salary = (
select max(salary)
from emp
where salary<(select max(salary) from emp)
)
SELECT MAX(salary)
employee_info
FROM
SELECT MAX(salary)
salary < (
WHERE
employee_info );
FROM
-----------------------------------------------------------------------------------
------------------------------------------------------------------
Question 4:
Find the second-highest salary along with the corresponding department name and
employee name.
Provide at least two different approaches for this without using window functions.
Discuss which approach is more optimized and why.
-----------------------------------------------------------------------------------
------------------------------------------------------------------
Question 5:
Consider a table containing user_id and restaurant_id (with three restaurants: A,
B, and C).
Write SQL queries to retrieve users who have ordered from both restaurants A and B.
Provide at least three different approaches and discuss which approach is the most
optimized and why.(interviewer want Boolean value approch)
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
Question 6:
You have a table containing emp_id, emp_name, and manager_id.
Write an SQL query to find the manager's name for each employee.
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
Question 7:
You have two tables: one with city names and their corresponding IDs, and the other
with city names.
Write an Excel function to fill in the city IDs in the second table.
-----------------------------------------------------------------------------------
------------------------------------------------------------------
Question 8:
In a table containing city, city_id, month, and amount,
write an Excel function to find the total amount for each city.
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
Question 9:
Find the total amount for each city for the 2nd month in the same table as in
Question 8.
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
Question 10:
In a pivot table, explain how to count distinct items.