#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    SQL Formatting help with to char Function


    Hey guys i have a problem with my SQL programming which i am learning at the moment. Currently here is my code:

    The question is: Show how many orders were placed in each month of 2012. (group by question, to char function)


    Code:
    select count(orderdate)
    from csorder
    group by orderdate;

    does anybody know where the to char function would occur?

    tables for reference
    Code:
    CSPRODUCT contains (PRODCODE, PRODNAME, CATCODE, PRICE, PARTOF_PRODCODE)
    CSCATEGORY contains (CATECODE, CATNAME)
    CSORDER contains (ORDERID, ORDERDATE, CUSTID, PAID)
    CSORDERLINE contains (ORDERID, PRODCODE, QUANTITY)
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,124
    Rep Power
    4274
    Originally Posted by theboxmike
    does anybody know where the to char function would occur?
    nowhere -- at least, not in mysql

    i'll move your thread to the oracle forum for you
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Oh sorry thanks! bit of a newbie to SQL
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Originally Posted by theboxmike
    The question is: Show how many orders were placed in each month of 2012. (group by question, to char function)
    Try this and see if it gives you the desired results:
    Code:
    select to_char( orderdate, 'yyyymm' ) as order_month, count(*) as order_count
     from  csorder
    group by to_char( orderdate, 'yyyymm' );

IMN logo majestic logo threadwatch logo seochat tools logo