TCS SQL INTERVIEW QUESTION | Categorize Customers Based on Conditions

 DROP TABLE IF EXISTS CustomerPurchases;


 CREATE TABLE CustomerPurchases (

    CustomerID INT,

    DateOfPurchase DATE,

    Revenue DECIMAL(10, 2),

    ModeOfPurchase VARCHAR(50),

    Product VARCHAR(100)

);


INSERT INTO CustomerPurchases (CustomerID, DateOfPurchase, Revenue, ModeOfPurchase, Product)

VALUES 

(1, '2024-03-01', 800.00, 'Online', 'Laptop'),

(1, '2024-04-01', 750.00, 'Online', 'Tablet'),

(1, '2024-05-01', 1200.00, 'In-Store', 'Smartphone'),

(1, '2024-06-01', 900.00, 'Online', 'Television'),

(1, '2024-07-01', 1300.00, 'In-Store', 'Gaming Console'),

(1, '2024-08-01', 1050.00, 'Online', 'Smartwatch'),

(2, '2024-01-15', 1500.00, 'In-Store', 'Refrigerator'),

(2, '2024-02-20', 2000.00, 'Online', 'Home Theater System'),

(2, '2024-03-25', 1200.00, 'In-Store', 'Washing Machine'),

(2, '2024-04-10', 600.00, 'Online', 'Microwave'),

(3, '2024-03-05', 1800.00, 'Online', 'Laptop'),

(3, '2024-05-15', 1200.00, 'Online', 'Camera'),

(3, '2024-05-10', 1000.00, 'Online', 'Smartphone'),

(3, '2024-06-25', 1100.00, 'Online', 'Smartwatch'),

(4, '2024-03-01', 150.00, 'Online', 'Mouse'),

(4, '2024-04-01', 200.00, 'Online', 'Keyboard'),

(4, '2024-05-01', 180.00, 'Online', 'Headphones'),

(4, '2024-06-01', 220.00, 'Online', 'Router'),

(4, '2024-07-01', 300.00, 'Online', 'External Hard Drive'),

(4, '2024-08-01', 450.00, 'Online', 'Monitor'),

(5, '2024-02-10', 100.00, 'In-Store', 'USB Cable'),

(5, '2024-05-05', 120.00, 'Online', 'Smart Speaker');


SELECT * FROM CustomerPurchases

Comments

Popular posts from this blog

50 Essential SQL Questions to Land Your Dream Job

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

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs