I have a table like below
CREATE TABLE Customers_History(Row_Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Cust_Name VARCHAR(255),
Created_Date DATE,
Cust_Status TINYINT)
The rows in the table are below
INSERT INTO Customers_History(Cust_Name, Created_Date, Cust_Status)
VALUES('Customer A', '20120516', 0),
('Customer B', '20120516', 0),
('Customer C', '20120516', 0),
('Customer A', '20120517', 1),
('Customer B', '20120517', 0),
('Customer C', '20120517', 0),
('Customer A', '20120520', 1),
('Customer B', '20120520', 0),
('Customer C', '20120520', 1),
('Customer A', '20120521', 0),
('Customer B', '20120521', 0),
('Customer C', '20120521', 1),
('Customer A', '20120526', 1),
('Customer B', '20120526', 1),
('Customer C', '20120526', 0);
I want a Query which Brings Output as Below by taking date as parameter
When i pass 20120517 as parameter for date in where class it should bring Customer A as its status changes from 0 to 1
Customer A
When i pass 20120520 as parameter for date in where class it should bring Customer C as its status changes from 0 to 1
Customer C
When i pass 20120526 as parameter for date in where class it should bring Customer B as its status changes from 0 to 1
Customer B
I want the Customers name for particular date whose status changed from 0 to 1 for the first time.
Note : When i pass 20120526 as parameter for date in where class it should not bring Customer A since Customer A Status Changed from 0 to 1 on 17 itself.
There you go: