Hello Sashi,
Thanks for your reply.
SELECT UserID,
COUNT(*) as Total_In_Outs , MIN(Date_Time) as FirstIn,
MAX(Date_Time) as LastOut FROM sample2 GROUP BY UserID
Worked but what if I have daily data like I want the data of daily. Like in out of 24th, 25th etc. separately..Here is the input
create table sample2 (UserID numeric (18,0), Reader varchar (20), Date_Time datetime );
Insert into sample2 values (123, 'In', '2015-08-24 06:00:00.000');
Insert into sample2 values (123, 'Out', '2015-08-24 07:00:00.000');
Insert into sample2 values (123, 'In', '2015-08-24 08:00:00.000');
Insert into sample2 values (123, 'Out', '2015-08-24 09:00:00.000');
Insert into sample2 values (123, 'In', '2015-08-24 10:00:00.000');
Insert into sample2 values (123, 'Out', '2015-08-24 11:00:00.000');
Insert into sample2 values (123, 'In', '2015-08-25 7:00:00.000');
Insert into sample2 values (123, 'Out', '2015-08-25 8:00:00.000');
Insert into sample2 values (123, 'In', '2015-08-25 08:15:00.000');
Insert into sample2 values (123, 'Out', '2015-08-25 11:00:00.000');
Insert into sample2 values (124, 'In', '2015-08-24 06:15:00.000');
Insert into sample2 values (124, 'Out', '2015-08-24 07:30:00.000');
Insert into sample2 values (124, 'In', '2015-08-24 08:00:00.000');
Insert into sample2 values (124, 'Out', '2015-08-24 09:30:00.000');
Insert into sample2 values (124, 'In', '2015-08-24 10:00:00.000');
Insert into sample2 values (124, 'Out', '2015-08-24 11:30:00.000');
Here for 123, I have entry for 24th and 25th and so need the data for both the dates. Please help.
Thanks,
Ashutosh Jha
http://tricksroad.com