DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Query help

  1. #1
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401

    Query help

    orders
    ----------
    orderid -Primkey
    createddate

    orderhistory
    -------------
    ordhistid
    orderid -foriegnkey
    orderstage(different stages for orders such as ordered,processed,mailed, delivered, reprocessed)
    created

    i would like to query count(orderid) orders created before 6months ago and need
    count how many times it changed stage after first time it delivered.is this possible at all

    example
    -----------
    orders
    =============
    3 - 12-DEC-2005

    orders history
    =================
    11-3- ordered - 12-dec-2005
    12-3-processed- 13-dec-2005
    13-3-mailed - 14-dec-2005
    14-3- delivered -15-dec-2005
    15-3- reprocessed-11-jan-2006
    16-3-mailed - 14-JAN-2006
    17-3- delivered -17-JAN-2006

    in this case it should give

    orderid-count
    ==================
    3-3

    any help is much appreciated

  2. #2
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,492

    Cool


    Try:
    Code:
    Select Count(Distinct Orderid) Orderid, Count(*) Stage_Count
      From Orders_History
     Where Trunc(Created) < Add_Months(Trunc(Sysdate),-6);

    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  3. #3
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    Thanks , i tried

    but i would like to count the hits after it hit delivered first time

    let's say

    11-3- ordered - 12-dec-2005
    12-3-processed- 13-dec-2005
    13-3-mailed - 14-dec-2005
    14-3- delivered -15-dec-2005
    15-3- reprocessed-11-jan-2006
    16-3-mailed - 14-JAN-2006
    17-3- delivered -17-JAN-2006

    for order 3 -it should display only 3
    5-3- reprocessed-11-jan-2006
    16-3-mailed - 14-JAN-2006
    17-3- delivered -17-JAN-2006


    also in system we have orders created before 12 months


    your time is much appreciated
    Last edited by prodadmin; 06-02-2006 at 09:18 AM.

  4. #4
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,492

    Cool


    Just add and group by orderid and orderstage to the query I posted.
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

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