Results 1 to 3 of 3

Thread: Weekly Totals

  1. #1
    Join Date
    Jan 2006
    Location
    Oakland, CA
    Posts
    9

    Unanswered: Weekly Totals

    Hi,

    I've searched for an answer to this question and could not find it.

    I have a table with a date field and a unique identifier field. I am trying to figure out how many records we have in this table, PER WEEK. Simple.

    Problem is, I can't figure out how to get that to happen in a query. Ideally I'd have results that looked like this:

    week 1: 23
    week 2: 100
    week 3: 75.


    Or something like this:

    1/1/07-1/7/07: 35
    1/8/07-1/14/07: 100
    1/15/07-1/21/07: 75

    Can this be done in one query?

    I'm not a techie, but I would love to find out how this could happen in one or two queries. Can someone offer a suggestion?

    Many thanks to the person who answers this question.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select datepart(ww,datefield) as week
         , count(*) as rows
      from daTable
    group 
        by datepart(ww,datefield)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2006
    Location
    Oakland, CA
    Posts
    9

    Perfect

    Wow, that is great. Thank you. That is just what I wanted. I have so much to learn!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •