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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:45:22+00:00 2026-06-12T01:45:22+00:00

I have a table with a couple of thousand rows: from this I need

  • 0

I have a table with a couple of thousand rows: from this I need to extract a total for column WTE for each value in column band, including those where the total is 0. I also need each total to be in a column of its own, so that I can easily update a summary table.

The code I have at present returns the values from the relevant rows:

SELECT 
   IF(band="E",WTE,0) AS `Band6_WTE`
FROM  `orthoptists` AS o
LEFT JOIN `instances` AS i
ON o.instance_FK = i.id
WHERE i.region = 14

But when I add SUM(), the return is incorrect (zero, when it should be several thousands):

SELECT 
   IF(band="E",SUM(WTE),0) AS `Band6_WTE`
FROM  `orthoptists` AS o
LEFT JOIN `instances` AS i
ON o.instance_FK = i.id
WHERE i.region = 14

I have looked at http://en.wikibooks.org/wiki/MySQL/Pivot_table, but I do not understand how that approach should be applied to my problem.

What should I do?

  • 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-06-12T01:45:23+00:00Added an answer on June 12, 2026 at 1:45 am

    you must sum if:

    SELECT
        SUM(IF(band="E",WTE,0)) AS `Band6_WTE`
    FROM  `orthoptists` AS o
    LEFT JOIN `instances` AS i
    ON o.instance_FK = i.id
    WHERE i.region = 14
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a large table (a couple of thousand rows) and I
I have a MySQL database table with a couple thousand rows. The table is
hi i have a table with couple of rows and each row there is
I have a table with a couple of rows with two cells in each
I have a couple hundred records in a table and I need to get
I have a couple of tables which look like this Table 1 user_id |
I have a couple of tables with similar structures like this: <table> <tbody> <tr>content</tr>
I have a MySQL-InnoDB table with 350,000+ rows, containing a couple of things like
I have a a table with a couple of hidden rows. What I want
I have a table inside a couple of nested divs. One column holds an

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.