AMAZON INTERVIEW QUESTION - Return orders with single product and only "PROMO" code associated

 DML Script: 


--Identify all orders linked to a single product with a "PROMO" discount value. 

--If an order is associated with multiple products or multiple discounts, it should not be included in the result.



DROP TABLE IF EXISTS Promotions;

GO


CREATE TABLE Promotions (

OrderID   INTEGER NOT NULL,

Product   VARCHAR(255) NOT NULL,

Discount  VARCHAR(255)

);

GO


INSERT INTO Promotions (OrderID, Product, Discount) VALUES 

(1, 'Item1', 'PROMO'),

(1, 'Item1', 'PROMO'),

(1, 'Item1', 'PROMO'),

(1, 'Item2', 'MARKDOWN'),

(2, 'Item2', NULL),

(2, 'Item3', 'MARKDOWN'),

(2, 'Item3', NULL),

(3, 'Item1', 'PROMO'),

(3, 'Item1', 'PROMO'),

(3, 'Item1', 'PROMO'),

(4, 'Item5', 'MARKDOWN'),

(4, 'Item5', 'MARKDOWN'),

(4, 'Item5', 'MARKDOWN'),

(5, 'Item8', 'MARKDOWN'),

(5, 'Item8', 'PROMO'),

(5, 'Item8', 'MARKDOWN');

GO

 

 SELECT * FROM Promotions

Comments

Popular posts from this blog

Mu Sigma SQL INTERVIEW QUESTION | Consecutive events count - Dataset 1

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

NTT DATA SQL INTERVIEW QUESTION | Solve 80/20 Pareto rule