I have a table with user states in it. I worte the following query to find persons who have never been in a 'ready' state for a given period of time. This query takes forever to run. Any way to make it better?
SELECT distinct A.UserName, A.UserID
FROM dbo.Activity A
WHERE A.BeginTime >= '2008-05-05 04:00:00'
and A.BeginTime < '2008-05-12 04:00:00'
and not exists
(SELECT *
FROM dbo.Activity A2
WHERE A2.BeginTime >= '2008-05-05 04:00:00'
and A2.BeginTime < '2008-05-12 04:00:00'
and A2.State = 'Ready'
and A2.UserID = A.UserID)
Also I have to find the people who have newly appeared in this catogory. So given a dataset of people who were never ready the previous week (obtained from the query above), give me those who newly appeared in this group yesterday.
So here is what is needed :
If previous week people who were not in 'ready' state were identified as
A
B
C
D
And yesterday we now have
A
B
C
D
Z
I need to identify Z
I tried to write a query with another not exists clause but it takes for ever to run.
Thanks,
Sumi.
SELECT distinct A.UserName, A.UserID
FROM dbo.Activity A
WHERE A.BeginTime >= '2008-05-05 04:00:00'
and A.BeginTime < '2008-05-12 04:00:00'
and not exists
(SELECT *
FROM dbo.Activity A2
WHERE A2.BeginTime >= '2008-05-05 04:00:00'
and A2.BeginTime < '2008-05-12 04:00:00'
and A2.State = 'Ready'
and A2.UserID = A.UserID)
Also I have to find the people who have newly appeared in this catogory. So given a dataset of people who were never ready the previous week (obtained from the query above), give me those who newly appeared in this group yesterday.
So here is what is needed :
If previous week people who were not in 'ready' state were identified as
A
B
C
D
And yesterday we now have
A
B
C
D
Z
I need to identify Z
I tried to write a query with another not exists clause but it takes for ever to run.
Thanks,
Sumi.