While working white Availability of Resources. I got struct here. Let me explain so expect to get some help here.
Considering a table Availability as below create script with sample records for better understanding.
CREATE TABLE availibility (
id int NOT NULL,
start_date date NOT NULL,
end_date date DEFAULT NULL,
status tinyint NOT NULL DEFAULT '1'
) ENGINE=InnoDB;
INSERT INTO availibility (id, start_date, end_date, status) VALUES (1,'2024-02-01', '2024-02-10', 1), (2,'2024-02-21','2024-02-29',1);
Now it returns result as below:
ID | Start Date | End Date | Status |
---|---|---|---|
1 | 2024-02-01 | 2024-02-10 | 1 |
2 | 2024-02-21 | 2024-02-29 | 1 |
While my expectations is to return in between row as well. Sample below.
ID | Start Date | End Date | Status |
---|---|---|---|
1 | 2024-02-01 | 2024-02-10 | 1 |
NULL | 2024-02-11 | 2024-02-20 | 0 |
2 | 2024-02-21 | 2024-02-29 | 1 |
Help will be appreciate. Thanks
2
Answers
I have change my answer
Of course! If you’ve modified the query so that the ID doesn’t play a role anymore, and it’s possible for a smaller ID to appear much later in the sequence, let’s test it. Could you please provide the modified query or any specific changes you’ve made to it? Once I have that information, I’ll be able to assist you further and test it accordingly.
https://dbfiddle.uk/5oi4khgB
Another way is, using UNION:
see: DBFIDDLE