Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Q) What is the output basis left join & inner join.

Table 1

Table 2

D
D

Solution:

Inner Join

D
Left Join

Q) How do I write this query efficiently?

SELECT o.order_id, o.order_date, o.order_amount, o.customer_name, o.email, o.address


FROM Orders o
Where o.customerid in (select customerid from Customers c ) AND o.order_date BETWEEN
'2022-01-01' AND '2022-12-31';

SOLUTION:
SELECT o.order_id, o.order_date, o.order_amount, o.customer_name, o.email, o.address
FROM Orders o
left join Customer c
ON o.customerid = c.customerid
WHERE o.order_date BETWEEN '2022-01-01' AND '2022-12-31'
Q) All employees are mapped to managers Sam and Mike. For employees mapped to manager
Mike, map them to new manager Shane

Solution:

SELECT Employees, CASE WHEN Manager = ‘Sam’ THEN ‘Sam

ELSE ‘Shane’ END AS Manager_Name

FROM Table

Q) Department wise second highest salary from North zone?

Select Employee_Name, Emp_salary

FROM (SELECT Employee_Name, Employee_Salary, ROW_NUMBER(Salary) OVER(Partition by


Zone, Department Order BY Salary DESC AS Rank FROM table_name)

WHERE Zone= ‘North’ AND Rank=2;

A N A1 100

B S A2150

C N A1 200

A N A1 100 2

C N A1 200 1

B S A2 150 1

Q) Identify employees in each department that got the highest hike in last year?

Table name : Employee_increments


empid, increment date, salary, department

SELECT Department, Empid, MAX(Salary)

FROM Employee_increments

WHERE YEAR(Increment_date) = ‘mention_last_year’

GROUP BY Department, Empid;


FROM EMp_increment T1

JOIN Emp_increment T2

ON YEAR(T1.increment_date) > YEAR(T2.increment_date)

Q) Identify the top 20% of customers based on order value?

Q) Write a query to identify d7 retention of users?

Date Retention_No

Jan1 100
Jan2 80
.
Jan7 40

Date1 Ren1 Date2 Ret2 DATEDIFF(


Jan1 100 Jan2 80

=<

Q) Identify users who made a consecutive purchase on days from user orders in last 7 days?
Product Analyst - OLA (Transportation)

Revenue Drop - 20% (Sharp)

KPI

Used Cases

Avg Rev d/d = $1M

Internal -

1. Update
2. Number of Rides - Increases / constant / decreases
3. Fair Prices - Inflation, stayed the same,
4. Time spent - Increase

External -

1. Strike , Festival
2. Competitor - Rides cheaper, add more, discount/ rewards

Activation Funnel -

1. Number of user - traffic (conversion)


2. Number of rides - Inc / Dec / Constant
3. Hit 4-5
4. Drop - Book
5. Drop - Waiting

You might also like