Solved

Self Join query to ID a pattern fo data Needed

Posted on 2009-04-01
5
239 Views
Last Modified: 2012-05-06
I have a table that has three fields.
acct_nbr
theID
datetime to the second.

I need a query that will allow me to find a pattern where sequential acct_nbr's numbers have been accessed by the same theID based on datetime to the second. Listed below is an example of the data. It does not represent the pattern I am trying to find.  While I can sort by acct_nbr,datetime, and theID I can not bring the required pattern to the forefront.  There are 20 millions records in the table.

All help is greatly appreciated.

Data looks like
acct_nbr                     datetime                                      theID
123911111      2007-12-28 23:01:54.000      206936
133333333      2007-12-28 22:19:15.000      969023
644444444      2007-12-28 23:00:28.000      999633
155555555      2007-12-29 08:10:40.000      590635

0
Comment
Question by:frogman22
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24041985
So the access has to take place during the SAME second?  Your requirement is unclear:
"sequential acct_nbr's numbers have been accessed by the same theID based on datetime to the second"


;with AccountsAccessed as
(select theid,[datetime] as tDate,acct_nbr
from SomeTable b
join
(select theid,[datetime]
from SomeTable
group by theid,[datetime]
having count(*)>1
)a
on a.theid=b.theid and b.[datetime]=c.[datetime]
)
select * from AccountsAccessed a1
join AccountsAccessed a2
on a1.theid=a2.theid
and a1.tdate=a2.tdate
and a1.acct_nbr=a2.acct_nbr-1

0
 

Author Comment

by:frogman22
ID: 24042365
Sorry for the confusion. I meant "to the second "in regards to sequential order.  Does the query sample need to be modified
0
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24042595
Try this

select a1.theid, a1.acct_nbr, a2.acct_nbr, a1.[datetime]
from YourTable a1 inner join YourTable a2
   on a1.theid = a2.theid and a1.[datetime] = a2.[datetime] and a1.acct_nbr = a2.acct_nbr+1
0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 500 total points
ID: 24042611
based on your last post this should work

select a1.theid, a1.acct_nbr, a2.acct_nbr, a1.[datetime]
from YourTable a1 inner join YourTable a2
   on a1.theid = a2.theid and a1.[datetime] = a2.[datetime]
0
 

Author Comment

by:frogman22
ID: 24042962
It is running. We will see what the results are:-)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now