DBAsupport.com Forums - Powered by vBulletin
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Urgent !! Finding New Cookies

  1. #11
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092

  2. #12
    Join Date
    Dec 2000
    Posts
    87
    I know what's explain plan here..but I think in my case..it doesn't help me too much...because I'm comparing result sets with more than 8 million records...

  3. #13
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    =================================================
    Your Query is:

    select distinct trunc(logdate),
    cookieid from weblog w1
    where not exists(
    select 1 from weblog w2
    where w1.cookieid=w2.cookieid
    and trunc(logdate)<=trunc(logdate-1));
    ====================================================

    What is the purpose of "trunc(logdate)<=trunc(logdate-1)" condition in the sub query?

  4. #14
    Join Date
    Dec 2000
    Posts
    87
    I guess it's not quite the way to put it..

    But the purpose is to compare the 'current' (whatever the date of the current record is) cookie with all the previous(whatever the date of the record is minus 1) cookies

  5. #15
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Perhaps, something like
    Code:
    SELECT a.cookie_id, 
           a.count(distinct cookie_id) total count, 
           b.today_count
    FROM
       weblog a,
       ( SELECT count(distinct cookie_id) today_count
         FROM weblog w2 , 
              (SELECT cookie_id, min(logdate) first_date
               FROM weblog
               GROUP BY cookie_id) iv
         WHERE w2.cookie_id = iv.cookie_id
         AND w2.logdate >= sysdate -1
         AND w2.logdate <= sysdate) b
    group by a.cookie_id
    Jeff Hunter

  6. #16
    Join Date
    Dec 2000
    Posts
    87
    I am not too sure if using 'Sysdate' is a right choice here...
    Due to the fact that I'm going through each of the records in the table, and each cookie of arecord is compared to 'all' the previous cookies appeared. That means a cookie in a record dated '2002/8/10' will compare to all cookied prior to '2002/8/10' . Hope it's clear, thanks.

  7. #17
    Join Date
    Aug 2002
    Location
    Bangalore, India
    Posts
    405
    Originally posted by marist89
    Perhaps, something like
    Code:
    SELECT a.cookie_id, 
           a.count(distinct cookie_id) total count, 
           b.today_count
    FROM
       weblog a,
       ( SELECT count(distinct cookie_id) today_count
         FROM weblog w2 , 
              (SELECT cookie_id, min(logdate) first_date
               FROM weblog
               GROUP BY cookie_id) iv
         WHERE w2.cookie_id = iv.cookie_id
         AND w2.logdate >= sysdate -1
         AND w2.logdate <= sysdate) b
    group by a.cookie_id
    Nope, we cant use dates as such. Date datatype contains the minute and seconds too. So, we should truncate the date column so that we can round it.

    My suggestion,

    Use function based index on logdate.
    -nagarjuna

  8. #18
    Join Date
    Dec 2000
    Posts
    87
    yes, time needs to be truncated here...as it was what I did in my original query. Only date is required.

  9. #19
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    I meant:

    Code:
    SELECT a.cookie_id, 
           a.count(distinct cookie_id) total count, 
           b.today_count
    FROM
       weblog a,
       ( SELECT count(distinct cookie_id) today_count
         FROM weblog w2 , 
              (SELECT cookie_id, min(logdate) first_date
               FROM weblog
               GROUP BY cookie_id) iv
         WHERE w2.cookie_id = iv.cookie_id
         AND iv.first_date >= sysdate -1
         AND iv.first_date <= sysdate) b
    group by a.cookie_id
    Jeff Hunter

  10. #20
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Originally posted by nagarjuna

    Nope, we cant use dates as such. Date datatype contains the minute and seconds too. So, we should truncate the date column so that we can round it.
    Come again?

    Code:
    SQL> select * from xyz;
    
    D
    -------------------
    09/30/2002 13:29:06
    10/30/2002 13:29:17
    10/15/2002 13:29:27
    
    SQL> select * from xyz
      2  where d >= to_date('10/30/2002','mm/dd/yyyy')
      3  and d < to_date('10/31/2002','mm/dd/yyyy')
      4  /
    
    D
    -------------------
    10/30/2002 13:29:17
    
    SQL> select * from xyz
      2  where trunc(d) = to_date('10/30/2002','mm/dd/yyyy');
    
    D
    -------------------
    10/30/2002 13:29:17
    Jeff Hunter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width