Hi,
I have a table similar to this,
create table #test
(
Organisation varchar(255),
MNO varchar(255),
[check-in date] date,
[check-out date] date,
[Room No] Varchar(255)
)
insert into dbo.#test
values ('MNO','A','20180503','20180507','5')
insert into dbo.#test
values ('MNO','B','20180505','20180513','3-a')
insert into dbo.#test
values ('MNO','A','20180507','20180604','7')
insert into dbo.#test
values ('MNO','A','20180604','20180615','9')
insert into dbo.#test
values ('MNO','B','20180604','20180615','3-a')
insert into dbo.#test
values ('MNO','C','20180604','20180615','2')
insert into dbo.#test
values ('CQA','A','21080601','20180613','11')
insert into dbo.#test
values ('CQA','A','20180603','20180614','12')
insert into dbo.#test
values ('CQA','B','20180602','20180604','14')
insert into dbo.#test
values ('CQA','B','20180604','20180614','13')
select organisation,
sum(case when [check-in date] = '20180604' Then 1 else 0 end) as checkin,
sum(case when [check-out date] = '20180604' Then 1 else 0 end) as [check-out] from #test
group by organisation
Actually, I'm expecting the output as below. I don't want any person who just changed the room to appear in the check-in or check-out column.
I believe it is something related to comparison between two rows and get the desired result. I've no idea how to start with.
.
Thanks for your assistance on this.