Hi.I need help with a query :)I have a web site for a free online game. It hosts player info, statistics and other stuff for leagues in this game. The game has a "business rule" :) :"It's not allowed for a player to be a member of and play for two teams (called squads) during a league."So I plan to help out the admins of the game to track down possible "double squaders". To do that I need to write a query against my SessionLog table (where I track all logins) to find login sessions that are:1. close to eachother (XX minutes, input parameter)2. have same ip address3. the username is different4. are in the same league (input parameter)Then I can get a list of possible doubles squadders and the admins can then check this Username/IP list against their game server logs to see if they actually played for two squads.The thing is I don't know how to write the query :P-----------------Sessionlog Table:CREATE TABLE [dbo].[SessionLog] ( [sessionID] [char] (40) PRIMARY KEY NONCLUSTERED , [leagueID] [int] NOT NULL , [userName] [varchar] (255) NOT NULL , [userIP] [varchar] (15) NOT NULL , [userHost] [varchar] (500) NOT NULL , [userType] [char] (1) NOT NULL , [userID] [int] NOT NULL , [sessionState] [tinyint] NOT NULL , [createdDate] [smalldatetime] NOT NULL , [lastAccessedDate] [smalldatetime] NOT NULL ) ON [PRIMARY]GO-----------------Example data:SELECT leagueID, userName, userIP, createdDateFROM SessionLogORDER BY createdDate DESCwill give you this:5 Damage 192.168.0.7 2002-12-12 22:03:005 Little 192.168.0.1 2002-12-12 22:03:005 Musta Tappaja 192.168.0.2 2002-12-12 22:01:005 Copy Guy 192.168.0.1 2002-12-12 22:01:005 Freedom B 192.168.0.4 2002-12-12 19:22:005 Nomad 192.168.0.8 2002-12-12 18:14:005 Polarizer 192.168.0.9 2002-12-12 17:50:005 bluecheese 192.168.0.9 2002-12-12 17:49:005 WannaPlay?! 192.168.0.9 2002-12-12 17:48:005 Zsl 192.168.0.3 2002-12-12 12:45:005 Brainbuster 192.168.0.5 2002-12-12 11:22:005 Johny 192.168.0.9 2002-12-12 11:01:00-----------------what I'm trying to do is write a query that from the above will return:5 Little 192.168.0.1 2002-12-12 22:03:005 Copy Guy 192.168.0.1 2002-12-12 22:01:005 Polarizer 192.168.0.9 2002-12-12 17:50:005 bluecheese 192.168.0.9 2002-12-12 17:49:005 WannaPlay?! 192.168.0.9 2002-12-12 17:48:00
.In other words a list of possible doublesquaders in the league with leagueID=5. The problem for me is that I don't know how to check if the row before and after another row is within XX minutes.Any help would be appreciated :)/ArgyleEdit: had some problems with the code tagEdited by - argyle on 01/06/2003 07:57:11