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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:08:56+00:00 2026-05-18T03:08:56+00:00

I am running the following queries against a database: CREATE TEMPORARY TABLE med_error_third_party_tmp SELECT

  • 0

I am running the following queries against a database:

CREATE TEMPORARY TABLE med_error_third_party_tmp
SELECT `med_error_category`.description AS category, `med_error_third_party_category`.error_count AS error_count
FROM
    `med_error_category` INNER JOIN `med_error_third_party_category` ON med_error_category.`id` = `med_error_third_party_category`.`category`
WHERE
    year = 2003
GROUP BY `med_error_category`.id;

The only problem is that when I create the temporary table and do a select * on it then it returns multiple rows, but the query above only returns one row. It seems to always return a single row unless I specify a GROUP BY, but then it returns a percentage of 1.0 like it should with a GROUP BY.

SELECT category, 
       error_count/SUM(error_count) AS percentage
  FROM med_error_third_party_tmp;

Here are the server specs:
Server version: 5.0.77
Protocol version: 10
Server: Localhost via UNIX socket

Does anybody see a problem with this that is causing the problem?

  • 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-18T03:08:57+00:00Added an answer on May 18, 2026 at 3:08 am

    Standard SQL requires you to specify a GROUP BY clause if any column is not wrapped in an aggregate function (IE: MIN, MAX, COUNT, SUM, AVG, etc), but MySQL supports “hidden columns in the GROUP BY” — which is why:

    SELECT category, 
           error_count/SUM(error_count) AS percentage
      FROM med_error_third_party_tmp;
    

    …runs without error. The problem with the functionality is that because there’s no GROUP BY, the SUM is the SUM of the error_count column for the entire table. But the other column values are completely arbitrary – they can’t be relied upon.

    This:

    SELECT category, 
           error_count/(SELECT SUM(error_count)
                          FROM med_error_third_party_tmp) AS percentage
      FROM med_error_third_party_tmp;
    

    …will give you a percentage on a per row basis — category values will be duplicated because there’s no grouping.

    This:

      SELECT category, 
             SUM(error_count)/x.total AS percentage
        FROM med_error_third_party_tmp
        JOIN (SELECT SUM(error_count) AS total
                FROM med_error_third_party_tmp) x 
    GROUP BY category
    

    …will gives you a percentage per category of the sum of the categories error_count values vs the sum of the error_count values for the entire table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running following PHP code to interact with a MS Access database. $odbc_con
I'm running the following query in Hypersonic DB (HSQLDB): SELECT (CASE foo WHEN 'a'
I tried running the following statement: INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION) SELECT (a.number,
I have the following scenario: I have a database with a particular MyISAM table
When running the following code it leaves out one row. When I do a
When running the following Java code, I get very accurate and consistent results in
When I am running the following statement: @filtered = map {s/ //g} @outdata; it is
I am currently running the following code based on Chapter 12.5 of the Python
Similar to this question , after running the following code the browser dialog does
I understand that using the === compares type, so running the following code results

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.