Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:20:56+00:00 2026-05-31T06:20:56+00:00

I’m having trouble with some MYSQL. The code below has been working fine until

  • 0

I’m having trouble with some MYSQL. The code below has been working fine until a week or two ago when it started grouping anything more recent than 21 Feb 2012 together. The first entry was 18th September 2011 so it hasn’t run for a whole year.

SELECT dept, time, COUNT(*) AS freq
FROM prefix_table1 a
INNER JOIN prefix_table2 b b ON a.author = b.username
GROUP BY WEEKOFYEAR(DATE(FROM_UNIXTIME(time)))
ORDER BY time ASC
LIMIT 24 

All I want to achieve with this query is to retrieve the number of entries which have occurred in each week.

Once I have that I process the UNIX stamp in PHP to get the week number in the year and suffix it with the year to allow the stats to work for more than 12 months.

Question is – where have I gone wrong? Why has it stopped working w/c 21st Feb 2012?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:20:57+00:00Added an answer on May 31, 2026 at 6:20 am

    The problem is that you’re grouping by a different set of fields than the one you’re selecting. That query has just worked by chance. I mean, you’ve been grouping by WEEKOFYEAR and selecting the time value. What the grouping actually does is “removing” the details and make a group with them applying a function (a count in this case).

    Now, you’re trying to show a detail while grouping at the same time, and that results in an incorrect query. For instance, this would work, but won’t show you a detail:

    SELECT dept, WEEKOFYEAR(DATE(FROM_UNIXTIME(time))) as aWeek, COUNT(*) AS freq
    FROM prefix_table1 a
    INNER JOIN prefix_table2 b b ON a.author = b.username
    GROUP BY dept, aWeek
    ORDER BY aWeek
    LIMIT 24
    

    A clear example of the wrong logic of your original query is: If you have grouped, let’s say, 20 records (the count would display 20)… which time would you display for ALL of them if you can only display 1 of those records?

    Edit:

    As @ypercube said, the previous query might not work depending on if you’re forcing the server to respect ansi standards or not. If that is the case, then you could try running the following (and a little bit unfriendlier) query:

    SELECT dept, WEEKOFYEAR(DATE(FROM_UNIXTIME(time))) as aWeek, COUNT(*) AS freq
    FROM prefix_table1 a
    INNER JOIN prefix_table2 b b ON a.author = b.username
    GROUP BY dept, WEEKOFYEAR(DATE(FROM_UNIXTIME(time)))
    ORDER BY aWeek
    LIMIT 24
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.