How to select the duplicate value if both are in the same interval

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patydsc
    New Member
    • Jul 2010
    • 2

    How to select the duplicate value if both are in the same interval

    Hi,

    can anyone help me to figure this out.
    Currently, i have this code:
    Code:
    select 
      t_stamp, 
      num 
    from table
    where num in 
       (select num from click_log 
        where t_stamp between '2010-07-21 12:00:00' 
        and '2010-07-21 13:00:00'
        group by num 
        having count(*) > 1)
    order by num;
    this code will get the duplicate values within interval of 1 hour. This is not the problem. the problem is how to get duplicate values for every 15 mins of time range (0-15,15-30,30-45,45-60) within interval of 1 hour.

    lets say if my records look like this:
    Code:
    tstamp              | num
    --------------------+-----
    2010-07-21 11:59:05 |  a
    2010-07-21 12:05:23 |  a
    2010-07-21 12:08:47 |  c
    2010-07-21 12:11:30 |  a
    2010-07-21 12:18:11 |  a
    2010-07-21 12:24:09 |  b
    2010-07-21 12:33:41 |  a
    2010-07-21 12:35:29 |  b
    2010-07-21 12:39:09 |  b
    2010-07-21 12:43:51 |  a
    2010-07-21 12:45:17 |  a
    2010-07-21 12:49:05 |  c
    2010-07-21 12:56:00 |  c
    2010-07-21 13:10:32 |  a
    
    the output should be look like this:
    
    tstamp              | num
    --------------------+-----
    2010-07-21 12:05:23 |  a    } in 0-15mins
    2010-07-21 12:11:30 |  a    }
    _________________________
    2010-07-21 12:33:41 |  a    } in 30-45mins
    2010-07-21 12:35:29 |  b    }
    2010-07-21 12:39:09 |  b    }
    2010-07-21 12:43:51 |  a    }
    _________________________
    2010-07-21 12:49:05 |  c    } in 45-60mins
    2010-07-21 12:56:00 |  c    }
    I appreciate any help.

    thanks :)
  • patydsc
    New Member
    • Jul 2010
    • 2

    #2
    fyi, i'm using postgres 8.2 :)

    Comment

    • rski
      Recognized Expert Contributor
      • Dec 2006
      • 700

      #3
      All ranges in one query? Can you use UNION clauses?

      Comment

      Working...