Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
hek78
Starting Member
10 Posts |
Posted - 2003-12-03 : 10:16:41
|
This is a sample Access tableIPAddress Time Byte10.65.30.85 8:25:14 2410.65.30.85 8:25:14 010.65.30.85 8:25:17 1010.65.30.86 8:26:18 3310.65.30.86 8:26:18 1010.65.30.86 8:27:33 2010.65.30.87 8:33:33 3310.65.30.87 8:33:40 2410.65.30.85 8:36:33 010.65.30.85 8:36:55 28IPAddress is in Text formatTime is in Date/Time FormatBytes is in Number FormatImagine the senario this way. User of one IP address log in at a particular time and download files. Another user of another IP log in. This particular user may download files again later so IP address may repeat.I would like to write a Query with a final table shownIPAddress TimeStart TimeEnd TimeDifference SumofByte10.65.30.85 8:25:14 8:25:17 0:00:03 3410.65.30.86 8:26:18 8:27:33 0:01:15 6310.65.30.87 8:33:33 8:33:40 0:00:07 5710.65.30.85 8:36:33 8:36:55 0:00:22 28Note the repeat of IP adress 10.65.30.85 and there is no session number for each login.How can I do it? Thanks! Need any Visual Basic Programming? Real headache |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2003-12-03 : 10:44:54
|
[code]select IPAddress,min(time) as TimeStart, max(time) as TimeEnd, datediff("s",min(time),max(time)) as TimeDifference, sum(byte) as SumOfBytefrom( select *, (select count(*) from ip b where b.IPAddress<>a.IPAddress and b.time >= a.time) as id from ip a ) agroup by id,IPAddressorder by min(time)[/code] |
 |
|
hek78
Starting Member
10 Posts |
Posted - 2003-12-03 : 11:39:48
|
Problem SolveWorks perfectly on my sample! Gonna try it on my system after a good night sleep.Thanks again. |
 |
|
|
|
|