How to find the counts for records inserted 30 minutes before [message #318311] |
Tue, 06 May 2008 08:19  |
VEDDETA
Messages: 54 Registered: May 2008
|
Member |
|
|
Hi,
How can I get the count for records which has been inserted 2hrs ago but less than 24 hrs before?
CREATE TABLE DATA (
Visitor_Id Varchar2(10),
time1 TIMESTAMP
);
My query is something like a)get me the count of the visitor who
visited 30 minutes ago.
b) Get me the count of all the visitors who visited more than 1 day ago
|
|
|
|
Re: How to find the counts for records inserted 30 minutes before [message #318318 is a reply to message #318312] |
Tue, 06 May 2008 08:45   |
VEDDETA
Messages: 54 Registered: May 2008
|
Member |
|
|
Hi!
Thanks for your instant reply.I have tried to find out the count of
a) all visitors who visited today 30 minutes ago
b) who visited in between 30 to 1 hr
c) who visited in between 2-24 hrs
d) who visited more than 1 day ago...
Below is the query.But I am not getting the proper count as expected.
SELECT Visitor_Id,
count(case when ( time1 > SYSDATE - 30/1440) then 1 end) "Less than 30 min",
count(case when (time1 > SYSDATE - 60/1440 and time1 < SYSDATE - 29/1440 ) then 1 end) "30 -60 Min",
count(case when (time1 > SYSDATE - 1440/1440 AND time1 < SYSDATE - 119/1440 ) then 1 end) "2 - 24 Hour"
FROM data GROUP BY Visitor_Id
|
|
|
|
|
|
|
|
|
Re: How to find the counts for records inserted 30 minutes before [message #318370 is a reply to message #318311] |
Tue, 06 May 2008 11:01   |
VEDDETA
Messages: 54 Registered: May 2008
|
Member |
|
|
I am very much thankful to you for guiding me! Thanks for your excellent support Michel.
I am herewith publisheing the SQL. Please do let me know for any concern if any.Thanks once again!
SELECT Visitor_Id,
COUNT(CASE
WHEN (Time1 > sysTimesTamp - INTERVAL '60' MINUTE) THEN 1
END) "< 1",
COUNT(CASE
WHEN Time1 > sysTimesTamp - INTERVAL '2' HOUR
AND Time1 <= sysTimesTamp - INTERVAL '1' HOUR THEN 1
END) "1 TO 2",
COUNT(CASE
WHEN Time1 >= sysTimesTamp - INTERVAL '24' HOUR
AND Time1 <= sysTimesTamp - INTERVAL '2' HOUR THEN 1
END) "2 TO 24",
COUNT(CASE
WHEN (Time1 < sysTimesTamp - INTERVAL '1' DAY) THEN 1
END) "> 1 Day"
FROM Date_Table
GROUP BY Visitor_Id
/
First line: Give me count of all customer who visted 60 minutes before
Second line: Give me count of all customer who visted in between 1 and 2 hr (Includes visitor from the 60th minute but less than 120 min)
...
Fourth line: Give me count of all customer who visited more than 1 day back.
|
|
|
|