Count the records per week

Posted on 2012-09-14
Last Modified: 2012-09-14
Hi guys,

Can someone please give the query syntax for counting the records of Field 1 per week (Field 2 with daily dates).
The week starts Monday.
Thank you
Question by:marian68
    LVL 47

    Accepted Solution

    In Access, this might look like:

    SELECT Year([Field2]) as TransYear, DatePart("ww", [Field2]) as TransWeek, Count(*) as WeekCount
    FROM yourTable
    GROUP BY Year([Field2]) as TransYear, DatePart("ww", [Field2]) as TransWeek
    LVL 12

    Assisted Solution

    datepart(year,field2) as [year],datepart(week,field2) as [week], count(field1) as [Count]
    from table
    group by datepart(week,field2),datepart(year,field2)
    order by datepart(year,field2), datepart(week,field2)
    LVL 12

    Expert Comment

    The access syntax that fyed posted will work in MS SQL too... no need for my re-post.

    Author Comment

    Thank you guys,
    Yes the first query worked.
    Thank you both

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now