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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:44:50+00:00 2026-06-10T08:44:50+00:00

Is there a way to performing calculations based on value of some other column

  • 0

Is there a way to performing calculations based on value of some other column within same or different table using the Default Value property (that is, the DEFAULT clause on a column definition) of MySQL ?

We can set static default values to any column but can we perform calculations or query other tables’ data ??

EDIT

Let’s say a table with column for marks and other with total_marks and third column percentage. How to set default value of percentage to be calculated from the former two columns

  • 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-10T08:44:52+00:00Added an answer on June 10, 2026 at 8:44 am

    No. The value for the DEFAULT clause must be a constant. (The one exception to this rule is the use of CURRENT_TIMESTAMP as a default value for a TIMESTAMP column.)

    As an alternative, you can use a TRIGGER to set a value for a column when a row is inserted or updated.

    For example, within a BEFORE INSERT FOR EACH ROW trigger, you can perform calculations from values supplied for other columns and/or query data from other tables.


    EDIT

    For the example given in the EDIT of the question, an example starting point for a trigger definition:

    CREATE TRIGGER mytable_bi 
    BEFORE INSERT ON mytable 
    FOR EACH ROW
    BEGIN
      SET NEW.percentage = (100.0 * NEW.marks) / NULLIF(NEW.total_marks,0);
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good way to specify column aliases when performing find() operations on
Is there a way to not block PyGTK while performing some expensive operation? I
Is there an accepted way of performing (pinch) zoom on a view that is
Is there a way of iterating through an array but performing an operation on
Is there a way to show the SQL that Django is running while performing
Is there a way to take into account the order of words when performing
Is there a way without using a script to run an UPDATE that won't
Is there a way to change the PLONE_SITE_ID from its default at plone.app.testing.interfaces without
I have a vertex/fragment shader that draws a rectangle performing many calculations based on
is there any way to prevent the WindowsForm button control from performing a line

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.