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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:16:42+00:00 2026-06-08T10:16:42+00:00

Bit of a newbie here. I’m currently working on a MySQL table that lists

  • 0

Bit of a newbie here. I’m currently working on a MySQL table that lists the details for different cars. I need a new field that is built up of the information from three other fields. So I have ‘Acceleration’, ‘Speed’ and ‘Braking’ which all contain double digit integers that are averaged out to another field I want to call ‘Average’.

The logic being ‘Acceleration’+’Speed’+’Braking’/3

I can’t seem to figure out the correct syntax to do this. I do specifically need this to be a field as I need those values to show up on other queries. I know a SELECT query can get the result values I need, but how to I conduct those values to a permanent field on that table?

Thanks in advance for any help on this.

  • 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-08T10:16:43+00:00Added an answer on June 8, 2026 at 10:16 am
    1. First, you’d need to alter the table schema to define the new column:

      ALTER TABLE my_table ADD COLUMN Average FLOAT;
      
    2. Next, update the table to set the values:

      UPDATE my_table SET Average = (Acceleration + Speed + Braking) / 3;
      
    3. Consider how to correctly set Average for newly inserted/updated data. Perhaps use triggers:

      CREATE TRIGGER calc_average_ins AFTER INSERT ON my_table FOR EACH ROW
      SET NEW.Average = (NEW.Acceleration + NEW.Speed + NEW.Braking) / 3;
      
      CREATE TRIGGER calc_average_upd AFTER UPDATE ON my_table FOR EACH ROW
      SET NEW.Average = (NEW.Acceleration + NEW.Speed + NEW.Braking) / 3;
      

    You might want to consider instead introducing this column in a view, to create the averages as required, on-the-fly, and thereby preventing it from becoming desynchronised from the underlying data values (but note you no longer achieve the performance benefit of having the values cached):

    CREATE VIEW my_view AS
    SELECT *, (Acceleration + Speed + Braking) / 3 AS Average FROM my_table;
    

    Finally, note that your average has no physical meaning in the real world (what would be its units?): a more meaningful metric may or may not be more suitable to your needs.

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

Sidebar

Related Questions

a bit of a PHP / MySQL newbie here... I've been building a PHP-based
im a little bit newbie on gdb so here goes: Im working on cpp
I'm a bit of a newbie to XPath, so I need some help figuring
I'm a bit new to Rails/RSpec/Capybara, so this is probably a newbie question, but
Bit of a JavaScript newbie here - I am firing this basic bit of
A bit of a Ruby newbie here - should be an easy question: I
Bit of a Rails newbie here so please bear with me. I am trying
being the C# newbie that I undoubtedly am, I'm a bit confused that you
Here's a bit of a newbie Python question about instance variables. Consider the following
I'm a newbie at MVC / Razor and I need a bit of direction.

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.