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 6365783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:20:16+00:00 2026-05-25T00:20:16+00:00

I’m having a problem with a query containing a GROUP BY. As part of

  • 0

I’m having a problem with a query containing a GROUP BY. As part of diagnosing it I removed the GROUP BY statement in order to see the raw data – however when I do that I get FEWER rows returned that I do with the GROUP BY.

To reproduce:

CREATE TABLE `test1` (
  `date` bigint(20) DEFAULT NULL,
  `quantity` int(11) DEFAULT NULL,
  `processed` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO `test1` VALUES (1312483084,3,2),(1312483084,1,2),(1312483148,1,2),(1312483148,1,2),(1314038654,1,2),(1314301805,1,2);

Now run my original SELECT (Complete with GROUP BY):

SELECT DATEDIFF(from_unixtime(test1.date), from_unixtime(1311801510)) DIV 28 AS date_idx,
min(DATEDIFF(from_unixtime(test1.date), from_unixtime(1311801510))) AS orig_date_idx,            SUM(test1.quantity) AS num_items,
IF(test1.processed in (2,3,4), 'Complete','Pending') as status
FROM test1
GROUP BY status, date_idx \G

You should get two rows returned:

*************************** 1. row ***************************
     date_idx: 0
orig_date_idx: 8
    num_items: 7
       status: Complete
*************************** 2. row ***************************
     date_idx: 1
orig_date_idx: 29
    num_items: 1
       status: Complete

Now remove the GROUP BY, ie:

SELECT DATEDIFF(from_unixtime(test1.date), from_unixtime(1311801510)) DIV 28 AS date_idx,
min(DATEDIFF(from_unixtime(test1.date), from_unixtime(1311801510))) AS orig_date_idx,            SUM(test1.quantity) AS num_items,
IF(test1.processed in (2,3,4), 'Complete','Pending') as status
FROM test1

All of a sudden you only get one row returned – the row that had date_idx == 1 in the original result has been merged into the entry for date_idx == 0

*************************** 1. row ***************************
     date_idx: 0
orig_date_idx: 8
    num_items: 8
       status: Complete

All ideas gratefully received!

  • 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-25T00:20:16+00:00Added an answer on May 25, 2026 at 12:20 am

    Frankly I’m surprised that it runs without just giving you an error for using aggregate functions without a group by, maybe has something to do with the fact that all your fields are calculated values. Anyway, get rid of all your aggregate functions to get to the underlying data.

    • 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 have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.