CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: SQL

  1. #1
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    SQL

    I have data in Access database. Sample data is:



    Timestamp Count Abort
    09/09/99 23 34
    09/10/99 34 12
    09/11/99 12 65
    09/12/99 56 42
    10/01/99 43 12
    10/02/99 43 54





    I would like this data to appear as follows:



    Timestamp Abort Count
    Sept 1999 186 201
    Oct 1999 89 102





    So, I want this data to be displayed in monthly intervals. Can someone let me know how?

    Please


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: SQL

    select month(timestamp), sum(abort), sum(count) from tablename group by month(timestamp)


  3. #3
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: SQL

    if I use 'group by timestamp', it is grouping the data for each timestamp (I have several item ID's for each timestamp). But I want data to be grouped for all timestamps. How can I do that?

    Thanks


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: SQL

    I didn't write anything about "group by timestamp" but about "group by month(timestamp). I assumed that you wanted to group by month, was I wrong?



  5. #5
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: SQL

    Hi Lothar,

    I tried to group by month, but that does'nt work.

    Thanks


  6. #6
    Join Date
    May 1999
    Posts
    3,332

    Re: SQL

    that's funny, because the code I posted was copied and pasted from an Access database Query window. So, I can guarantee, that it did work.
    Could you post the SQL of your query that doesn't work?


  7. #7
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: SQL



    SELECT format(timestamp,"mmm yyyy"), sum(count), sum(f100tme), sum(abort)
    FROM cmlap100
    GROUP BY month(timestamp)
    ORDER BY timestamp;





    Thanks


  8. #8
    Join Date
    May 1999
    Posts
    3,332

    Re: SQL

    I see, the expression specified in the GROUP BY clause must also occur in the SELECT list.
    Thus write it like this:
    SELECT format(timestamp,"mmm yyyy"), ...
    GROUP BY format(timestamp,"mmm yyyy")
    ...

    I'm not sure but "GROUP BY 1" might also work in Access (1 stands as a placeholder for the first expression in the select list).


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

Featured