Amazon BIE 1 interview SQL question and answer

amazon logo
amazon
BIE 1
April 7, 20254 reads

Summary

I had an interview for a BIE 1 role at Amazon where I was asked two specific SQL questions, which I have provided along with my answers.

Full Experience

Question 1

month            revenue
2001-01-01         650
2001-02-01        1200
2001-03-01         100
2001-04-01        1100
.
.
.
.2020-12-01       5000

Write SQL query to get the running total of the revenue to get below desired output: With Year and revenue and running total of revenue

Answer

SELECT 
    YEAR(month) AS Year,
    Revenue,
    SUM(revenue) OVER (ORDER BY YEAR(month)) AS Running_Total
FROM Table
ORDER BY YEAR(month);

Question 2

Given EMPLOYEES table with 3 columns: EMPLID, EMP_NAME, SUPERVISOR_ID.

Write a query to return the following columns for every employee: name of the employee and name of the employee's supervisor.

Answer

SELECT E.EMP_NAME,
        S.EMP_NAME
FROM EMPLOYEES E
LEFT JOIN EMPLOYEES S
 ON E.SUPERVISOR_ID = S.EMPLID;

Interview Questions (2)

Q1
SQL Running Total of Revenue by Year
Other

Given a table with month and revenue columns:

month            revenue
2001-01-01         650
2001-02-01        1200
2001-03-01         100
2001-04-01        1100
.
.
.
.2020-12-01       5000

Write an SQL query to get the running total of the revenue, displaying Year, Revenue, and Running_Total.

Q2
SQL Self-Join for Employee and Supervisor Names
Other

Given an EMPLOYEES table with three columns: EMPLID, EMP_NAME, SUPERVISOR_ID.

Write a query to return the following columns for every employee: the name of the employee and the name of the employee's supervisor.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!