I am trying to get the first and last days for the following where date_next_compare is less than 28.
I want to see two rows:
ID_NUM, 1/4/22 as first date, 1/10/22 as last date
ID_NUM, 12/19/22 as first date, 12/27/22 as last date.
I tried doing min and max where date_next_compare is less than 28 but it gives me 1/4/22 and 12/27/22. Thanks.
CREATE TABLE ADMITS
(
ID_NUM INT
,SERVICE_DATE DATE NULL
,NEXT_SERV DATE NULL
,DATE_NEXT_COMPARE INT NULL
)
INSERT INTO ADMITS (ID_NUM, ,SERVICE_DATE ,NEXT_SERV,DATE_NEXT_COMPARE)
VALUES
(770577602, '1/4/2022', '1/7/2022',3)
,(770577602, '1/7/2022', '1/10/2022',3)
,(770577602, '1/10/2022', '12/19/2022',343)
,(770577602, '12/19/2022', '12/20/2022',1)
,(770577602, '12/20/2022', '12/21/2022',1)
,(770577602, '12/21/2022', '12/27/2022',6)
,(770577602, '12/27/2022', NULL,NULL);
8