Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mysql count by week help

    Hi All

    I have a database with a table called tickets, the table has many columns but basically the ones i want are date and subject
    date is stored as datetime eg 14-06-04 10:33:39
    subject column has many different entries but i would like to only select where subject Like 073

    I currently have a query that counts the number of occurrences per subject
    Code:
    SELECT COUNT(*) AS `cnt`, `subject` FROM tickets GROUP BY `subject` ORDER BY `cnt`
    I would like to change this to count the total number of tickets per week where subject = 073

    output should look like

    Week Tickets
    01-06-14 5
    08-06-14 4
    15-06-14 2


    if anyone could help that would be greatly appreciated

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,719
    Thanks
    25
    Thanked 662 Times in 661 Posts
    Just add a where clause to the query, BUT what do you mean by
    where subject Like 073
    Does that mean LIKE %073, or LIKE 073%, or LIKE %073%?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New Coder
    Join Date
    Jun 2005
    Location
    Blackpool. UK
    Posts
    98
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Chris

    Indifference will be the downfall of mankind, but who cares?


  •  

    Posting Permissions

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