I have a table called #TimeAtHome
. It includes an address
, the date
and a flag atHome
to indicate if the person was at home that day. I need to capture the min
and max
date
for every grouping the person is not at home (0
) for each address
.
Here is some sample code:
create table #TimeAtHome (
[address] varchar(100),
[date] date,
[atHome] bit
)
insert into #TimeAtHome
values ('123 ABC Street', '2020-01-01', '1'),
('123 ABC Street', '2020-01-02', '1'),
('123 ABC Street', '2020-01-03', '0'),
('123 ABC Street', '2020-01-04', '0'),
('123 ABC Street', '2020-01-05', '0'),
('123 ABC Street', '2020-01-06', '0'),
('123 ABC Street', '2020-01-07', '1'),
('123 ABC Street', '2020-01-08', '0'),
('123 ABC Street', '2020-01-09', '0'),
('123 ABC Street', '2020-01-10', '1'),
('777 Hello Ct', '2020-01-01', '1'),
('777 Hello Ct', '2020-01-02', '1'),
('777 Hello Ct', '2020-01-03', '1'),
('777 Hello Ct', '2020-01-04', '0'),
('777 Hello Ct', '2020-01-05', '1'),
('777 Hello Ct', '2020-01-06', '1')