T-SQL query that fetches records where the person’s first and last call of the day is to the same person.
use below script to create table and insert some sample data
CREATE TABLE PhoneLog
(
ID INT,
FromPhoneNumber Varchar(100),
ToPhoneNumber Varchar(100),
Starttime DateTime,
EndTime DateTime
)
GO
INSERT INTO PhoneLog Values
(101,9878650055,9878650002,'2016-10-09 12:17:48.483','2016-10-09 12:20:48.483'),
(101,9878650055,9878650000,'2016-10-09 13:17:48.483','2016-10-09 13:20:48.483'),
(101,9878650055,9878650008,'2016-10-09 14:17:48.483','2016-10-09 14:20:48.483'),
(101,9878650055,9878650000,'2016-10-09 15:17:48.483','2016-10-09 15:20:48.483'),
(101,9878650055,9878650002,'2016-10-09 20:17:48.483','2016-10-09 20:20:48.483'),
(102,9878650051,9878650099,'2016-10-09 12:17:48.483','2016-10-09 12:20:48.483'),
(102,9878650051,9878650099,'2016-10-09 12:21:48.483','2016-10-09 12:25:48.483'),
(102,9878650051,9878650099,'2016-10-09 12:29:48.483','2016-10-09 12:31:48.483'),
(102,9878650051,9878650077,'2016-10-09 20:29:48.483','2016-10-09 20:35:48.483')
GO