0% found this document useful (0 votes)
117 views5 pages

Swiggy (BA) - Technical Interview (

Uploaded by

viditshahu45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views5 pages

Swiggy (BA) - Technical Interview (

Uploaded by

viditshahu45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Swiggy (BA) - Technical Interview (SQL, Excel)

Time- 1.5 hr

Question 1: Explain Windows functions and


Consider a table with the following columns:

dep_name | Salary | Rank | Dense_Rank | Row_number


------------------------------------------
A | 20k | 1 | 1 | 1
A | 20k | 1 | 1 | 2
A | 20k | 1 | 1 | 3
B | 15k | 4 | 2 | 4
B | 15k | 4 | 2 | 5
C | 10k | 6 | 3 | 6

first fill this column manually and then


write queries to calculate the Rank, Dense_Rank, and Row_number for each row
without using partitioning.

select dep_name, rank() over(order by Salary desc) as rnk from Emp


select dep_name, dense_rank() over(order by Salary desc) as rnk from Emp
select dep_name, row_number() over(order by Salary desc) as rnk from Emp

-----------------------------------------------------------------------------------
------------------------------------------------------------

Question 2:
Given two tables, Table-A and Table-B, with the following data:

Table-A | Table-B
---------------------
1 | 1
1 | 2
NULL | NULL

Provide the correct output for:

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

full outer join:

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

SELECT DISTINCT salary


FROM employees
WHERE salary NOT IN (
SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1
)
ORDER BY salary DESC
LIMIT 1;

select salary from emp e1


where n-1 = ( select count(distinct salary)
from emp e2
where e2.salary > e1.salary )

-----------------------------------------------------------------------------------
------------------------------------------------------------------

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.

You might also like