customerNumber ORDER BY paymentDate) AS customerRunningTotal, AVG(amount) OVER ( PARTITION BY customerNumber ORDER BY paymentDate) AS customerRunningAverage FROM payments;
BY customerNumber) - orderValue, 2) AS belowMax, ROUND(orderValue - MIN(orderValue) OVER (PARTITION BY customerNumber), 2) AS aboveMin FROM (SELECT o.orderNumber, o.customerNumber, SUM(od.quantityOrdered * od.priceEach) AS orderValue FROM orders o JOIN orderdetails od ON o.orderNumber = od.orderNumber GROUP BY o.orderNumber, o.customerNumber) AS ordersWithValues;
salesRepEmployeeNumber ORDER BY earliestOrder) AS serialNumber FROM (SELECT c.customerNumber, c.customerName, c.salesRepEmployeeNumber, MIN(o.orderDate) AS earliestOrder FROM customers c JOIN orders o ON c.customerNumber = o.customerNumber WHERE c.salesRepEmployeeNumber IS NOT NULL GROUP BY c.customerNumber, c.salesRepEmployeeNumber ) AS co;
AS rowNumber, RANK() OVER (ORDER BY employeeCount) AS rankNumber, DENSE_RANK() OVER (ORDER BY employeeCount) AS denseRankNumber, CUME_DIST() OVER (ORDER BY employeeCount) AS cumeDist FROM (SELECT o.officeCode, city, COUNT(*) AS employeeCount FROM offices o JOIN employees e ON o.officeCode = e.officeCode GROUP BY o.officeCode, city) AS oe;
customerNumber ORDER BY orderValue DESC) AS higherBy FROM (SELECT o.orderNumber, o.orderDate, o.customerNumber, SUM(od.quantityOrdered * od.priceEach) AS orderValue FROM orders o JOIN orderdetails od ON o.orderNumber = od.orderNumber GROUP BY o.orderNumber, o.customerNumber) AS ordersWithValues;
ROUND(amount - LAST_VALUE(amount) OVER customersWindow, 2) AS diffLast, ROUND(amount - NTH_VALUE(amount, 2) OVER customersWindow, 2) AS diffSecond FROM payments WINDOW customersWindow AS (PARTITION BY customerNumber ORDER BY amount DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING); First, Last & Nth Value
spent on each order on Amazon. Output the customer’s name, order details, and the percentage of their total spend for each order transaction rounded to the nearest whole number. Amazon Interview Question
traveling distance and cost for each ride. For each date, find the difference between the distance per dollar for that date and the average distance per dollar for that month. Uber Interview Question
number of hosts registered as the growth metric. rate_of_growth = 100 * (hosts_registered_this_year - hosts_registered_last_year) / hosts_registered_last_year Airbnb Interview Question
model to identify propensity of fraud claims. List the top 5 percentile claims identified by the model from each state in the US. Display the policy number, state, claim cost, and fraud score for each result. Netflix Interview Question