Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Posts
    53

    Unanswered: records for between day range.

    Hi,

    I am trying to get transaction for certain time frame. How can i get from folloing query, is there something wrong with it!!

    select user_id,sum(elapsed_minutes)
    from test
    where logon_day between to_char(sysdate,'DD-MON-YYYY')and (to_char(sysdate-1,'DD-MON-YYYY'))
    group by user_id

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Wrong? Who can tell ... the most obvious reason - if the LOGON_DAY column is of a DATE datatype - is that you don't use TO_CHAR function against the SYSDATE function as it already returns date.

    Therefore, it would be
    Code:
    ... WHERE logon_day BETWEEN sysdate AND sysdate - 1
    If, on the other hand, LOGON_DAY is of a CHARACTER datatype, then you should consider redesigning the table as storing dates into character columns bring nothing but trouble.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    or the order of the comparison is backwards
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    and I strongly think that the code should be written like this
    Code:
    select user_id,sum(elapsed_minutes)
    from test
    where logon_day between trunc(sysdate-1) and trunc(sysdate) 
    group by user_id;
    Last edited by beilstwh; 08-19-08 at 10:25.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    Type of Condition Operation Example 
    [NOT] BETWEEN x AND y
     [Not] greater than or equal to x and less than or equal to y.
     SELECT * FROM employees
      WHERE salary
      BETWEEN 2000 AND 3000;
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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