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

Thread: Need Help with Date Buckets - Logic

  1. #1
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    41

    Need Help with Date Buckets - Logic

    Hello Friends,
    I want to know a best way to generate a report on a product sales by weekly, monthly, quarterly and yearly.

    Here is the sample data:

    Date Product Count
    01/01/2005 apple 50
    01/01/2005 apple 50
    01/03/2005 apple 100
    01/05/2005 apple 80
    01/10/2005 apple 100


    I want the results in this format :

    Product WeeklySale Monthly Quarterly Yearly
    Apple 50 100 200 1000

    Can you please help me with the logic or any oracle function I could use ?
    Milind
    -----------------------------
    www.milinds.com
    My Private World on the Web !

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

    Cool Nice assignment

    And you want someone to do this homework assignment for you?

    If you really want to learn something, the best way is to try doing it yourself.


    Hint: Take a look at these functions: TO_CHAR(), CASE, DECODE(), COUNT() and SUM().
    Also check out GROUP BY...
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  3. #3
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    41
    Well, that was not really a homework assignment ..but i was able to do it myself .. just needed some idea on logic .. not plsql really ..

    I did it myself with select-case

    Select /*+ PARALLEL(DomainCountWeekly,8) */ product,
    SUM (CASE WHEN Week_Starting_Day BETWEEN sysdate-6 AND sysdateTHEN 1 ELSE 0 END) AS "0-6d",
    SUM (CASE WHEN Week_Starting_Day BETWEEN sysdate-7 AND sysdate THEN 1 ELSE 0 END) AS "Weekly",
    SUM (CASE WHEN Week_Starting_Day BETWEEN sysdate-30 AND sysdate THEN 1 ELSE 0 END) AS "Monthly",
    SUM (CASE WHEN Week_Starting_Day BETWEEN sysdate-90 AND sysdate THEN 1 ELSE 0 END) AS "Qtrly",
    SUM (CASE WHEN Week_Starting_Day BETWEEN sysdate-365 AND sysdate THEN 1 ELSE 0 END) AS "Yearly"
    From Salestable
    Where ...
    ...
    Milind
    -----------------------------
    www.milinds.com
    My Private World on the Web !

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