I have a rain forecast table that predicts the expected rainy date of two cities. The table looks like this:
CREATE TABLE raincheck(
city varchar(255),
expected_rain_date date,
actual_rain_date date);
INSERT INTO raincheck
(city,expected_rain_date,actual_rain_date) VALUES
('NYC','2001-02-02',null),
('NYC','2001-02-11',null),
('NYC','2001-03-20','2001-03-21'),
('NYC','2001-03-25',null),
('NYC','2001-04-10',null),
('NYC','2001-04-12','2001-04-12'),
('LDN','2001-02-03',null),
('LDN','2001-02-07','2001-02-07'),
('LDN','2001-03-11',null),
('LDN','2001-03-12',null),
('LDN','2001-03-17',null),
('LDN','2001-03-20','2001-03-20');
SELECT * FROM raincheck;
Since the actual rainy is not always accurate, I need a table with the time duration between the first expected rain date and the latest actual rain date. The result looks like this:
CREATE TABLE rainresult(
city varchar(255),
expected_rain_date date,
actual_rain_date date);
INSERT INTO rainresult
(city,expected_rain_date,actual_rain_date) VALUE
('NYC','2001-02-02','2001-03-21'),
('NYC','2001-03-25','2001-04-12'),
('LDN','2001-02-03','2001-02-07'),
('LDN','2001-03-11','2001-03-20');
SELECT * FROM rainresult;
I think the query may have something to do with NULL, like
SELECT * FROM rainresult WHERE actual_rain_date IS NOT NULL;
but I can't filter the expected_rain_date