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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:37:26+00:00 2026-05-23T14:37:26+00:00

I need to return average for each of 12 columns I have in a

  • 0

I need to return average for each of 12 columns I have in a table in DB. MySQL allows one to get average for one column only. The following query (for one column) works:

SELECT station_id, AVG(jan) AS avg_jan
FROM `climate_data`

WHERE element_name = "Temp_mean_mly" AND jan <> -999999  
GROUP BY station_id 

and the following (for multiple columns) does not (I get syntax error):

SELECT station_id, AVG(jan) AS avg_jan, AVG(feb) AS avg_feb, ... , 
AVG(dec) AS avg_dec 
FROM `climate_data`

WHERE element_name = "Temp_mean_mly" 
AND jan <> -999999 
AND feb <> -999999
AND ... 
AND dec <> -999999 
GROUP BY station_id 

Do I have to use 12 sub-queries to achieve the result I need?

  • 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-23T14:37:26+00:00Added an answer on May 23, 2026 at 2:37 pm

    1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘dec)

    dec is a reserved MySQL keyword; changing it to `dec` in your query would probably fix that error for you :).

    Edit: note that you’re also using it in the WHERE clause; it might work there (as it’s unlogical for MySQL to find a keyword there), but keep it in mind that you might also have to escape that one 🙂

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

Sidebar

Related Questions

I need to calculate the average value for each month. Currently I have 2
I need to return server time from a webservice. I've got the following code:
I need to return two values at a time, so I have: class IterableObject(object):
I have need to return multiple results from a subquery and have been unable
I have a table called Sessions with two datetime columns: start and end. For
I have the following SQL: select Username, COUNT(DISTINCT Message) as Count, AVG(WordCount) as Average,
I have a table that contains items, buyprice, and sellprice. I need to figure
I have a two-dimensional array of data. I need to average every two rows,
This is a complex one. But I have a table which has a DATETIME
I have a simple 3 column csv file that i need to use python

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.