Amazon Interview Questions & Answers
Amazon Interview Questions & Answers
Question 1:
You have two tables: Product and Supplier.
- Product Table Columns: Product_id, Product_Name, Supplier_id, Price
- Supplier Table Columns: Supplier_id, Supplier_Name, Country
Write an SQL query to find the name of the product with the highest price in each
country.
Answer:
SELECT
s.Country,
p.Product_Name,
p.Price
FROM
Product p
JOIN
Supplier s ON p.Supplier_id = s.Supplier_id
WHERE
(s.Country, p.Price) IN (
SELECT
s2.Country,
MAX(p2.Price)
FROM
Product p2
JOIN
Supplier s2 ON p2.Supplier_id = s2.Supplier_id
GROUP BY s2.Country
);
Question 2:
You have two tables: Customer and Transaction.
- Customer Table Columns: Customer_id, Customer_Name, Registration_Date
- Transaction Table Columns: Transaction_id, Customer_id, Transaction_Date,
Amount
Write an SQL query to calculate the total transaction amount for each customer for
the current year. The output should contain Customer_Name and the total amount.
Answer:
SELECT
c.Customer_Name,
SUM(t.Amount) AS Total_Amount
FROM
Customer c
JOIN
Transaction t ON c.Customer_id = t.Customer_id
WHERE
YEAR(t.Transaction_Date) = YEAR(CURDATE())
GROUP BY
c.Customer_Name;
Question 3:
Write an SQL query to find customers who have not made any transactions this
year.
Answer:
SELECT
c.Customer_Name
FROM
Customer c
LEFT JOIN
Transaction t ON c.Customer_id = t.Customer_id
AND YEAR(t.Transaction_Date) = YEAR(CURDATE())
WHERE
t.Transaction_id IS NULL;
Question 4:
Find the third highest salary from the Employee table using DENSE_RANK.
Answer:
WITH SalaryRank AS (
SELECT
Salary,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS Rank
FROM
Employee
)
SELECT
Salary
FROM
SalaryRank
WHERE
Rank = 3;
Question 5:
Write an SQL query to fetch the total number of transactions and the average
transaction amount for each customer.
Answer:
SELECT
c.Customer_Name,
COUNT(t.Transaction_id) AS Transaction_Count,
AVG(t.Amount) AS Average_Amount
FROM
Customer c
JOIN
Transaction t ON c.Customer_id = t.Customer_id
GROUP BY
c.Customer_Name;
Question 1:
You have a DataFrame called df_sales with columns Product_Name, Country, and
Price. Write a pandas code to find the name of the product with the highest price in
each country.
Answer:
df_sales.loc[df_sales.groupby('Country')['Price'].idxmax()]
Question 2:
You have two DataFrames: df_customer with columns Customer_id,
Customer_Name, and Registration_Date, and df_transaction with columns
Transaction_id, Customer_id, Transaction_Date, and Amount. Write a pandas code
to calculate the total transaction amount for each customer for the current year.
Answer:
import pandas as pd
from datetime import datetime
current_year = datetime.now().year
df_transaction['Transaction_Date'] =
pd.to_datetime(df_transaction['Transaction_Date'])
df_transaction_current_year =
df_transaction[df_transaction['Transaction_Date'].dt.year == current_year]
df_total =
df_transaction_current_year.groupby('Customer_id')['Amount'].sum().reset_index()
df_total = df_total.merge(df_customer[['Customer_id', 'Customer_Name']],
on='Customer_id')
Question 3:
You have a DataFrame df with columns Employee_ID, Employee_Name, and
Salary. Write pandas code to fetch the third highest salary using rank.
Answer:
Question 4:
You have a DataFrame df with columns Transaction_ID, Customer_ID, and
Amount. Write a pandas code to calculate the average transaction amount for each
customer.
Answer:
df_avg = df.groupby('Customer_ID')['Amount'].mean().reset_index()
Question 5:
You have two DataFrames df1 and df2. Write pandas code to merge them on a
common column 'ID'.
Answer:
Question 1:
Tell us about a time when you had to support a decision you disagreed with. How
did you handle it, and what was the result?
Question 2:
Describe an instance where you went above and beyond to build or regain trust
with a colleague or client. What was the situation, and what were the outcomes?
Question 3:
Can you share an example of when you had to find an innovative solution to a
complex problem? How did you simplify the process or solution for everyone
involved?
Question 4:
Tell us about a situation where you had to adapt quickly to changes and handle a
challenging situation effectively.
Question 5:
Describe a time when you led a project that had ambiguous requirements. How did
you navigate through it?
Question 1:
Write the formula to sum values in column B where the corresponding values in
column A are greater than 10.
Answer:
=SUMIFS(B:B, A:A, ">10")
Question 2:
Write the formula to count the number of cells in column C where the value is
"Completed".
Answer:
=COUNTIFS(C:C, "Completed")
Question 3:
Write the formula to find the value in column B corresponding to the maximum
value in column A.
Answer:
Question 4:
Explain how to create a pivot table that shows the total sales by product category
from a dataset containing columns for Sales, Product_Category, and Region.
Answer:
Question 5:
Write a formula to find the average sales in column B where the values in column
A are "East" and column C is greater than 100.
Answer:
=AVERAGEIFS(B:B, A:A, "East", C:C, ">100")
THANKS !!
YouTube:
https://youtube.com/@shakrashamim?si=ucGSJ3mkKv8Lk7MQ
Instagram:
https://www.instagram.com/shakra.shamim/?igshid=OTJlNzQ0NWM%3D
LinkedIn:
https://in.linkedin.com/in/shakra-shamim-8ab3a1233
Telegram:
t.me/Data_geeks_by_Shakra_Shamim