PL/SQL return count for all dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaffer
    New Member
    • Oct 2011
    • 2

    PL/SQL return count for all dates

    Code:
    SELECT trunc(sysdate) dt, count(*) as count
    FROM ATM_MONITOR.ATM_PROBLEM
    WHERE trunc(sysdate) = trunc(create_time)
    union
    SELECT trunc(sysdate)-1 dt, count(*) as count
    FROM ATM_MONITOR.ATM_PROBLEM
    WHERE trunc(sysdate)-1 = trunc(create_time)
    union
    SELECT trunc(sysdate)-2 dt, count(*) as count
    FROM ATM_MONITOR.ATM_PROBLEM
    WHERE trunc(sysdate)-2 = trunc(create_time)
    It returns
    DT COUNT
    --------------------------
    19.10.2011 741
    18.10.2011 498
    17.10.2011 918


    How can I get this code in one statment???
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I'm surprised that it runs in the first place unless PL/SQL doesn't require the group by clause.

    You can just use the BETWEEN operator to combine your filter clauses. And bring in the create_time as opposed to the sysdate in your SELECT clause.

    Comment

    • irfanEmmaneul
      New Member
      • Aug 2014
      • 2

      #3
      the code can be created in expression

      Comment

      Working...