Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I enter formula in the column for MySQL database?

I wonder if the above can operate the column like the excel.

eg. same row. column 1 : A, column 2 : b, column 3 : A + b.

like image 808
King Avatar asked Aug 22 '10 11:08

King


People also ask

How do I create a calculated column in MySQL?

MySQL generated column's syntax First, specify the column name and its data type. Next, add the GENERATED ALWAYS clause to indicate that the column is a generated column. Then, indicate whether the type of the generated column by using the corresponding option: VIRTUAL or STORED .

Can you do calculations in MySQL?

MySQL provides several functions that you can use to perform calculations on dates, for example, to calculate ages or extract parts of dates.

How do you create a formula in a database?

Entering a formula in a database field. Choose Define Fields from the Layout menu. Select a field in the list or define a new field, choose Calculation or Summary from the pop-up menu, and click Create. If you're modifying a formula for an existing field, click Modify.

How do you store math equations in a database?

Store the equations in TEX or MATHML format in database[which will be basically strings]. Retrieve and render it on webpage using MathJax . Using MathJax equations can be rendered in many way, mainly - HTML-CSS,MathML and SVG.


1 Answers

You can't have columns that automatically contain some neighbouring cell's value or do some calculations with it.

However, in a mySQL query, you can do all the things Excel can, and much much more.

For example, to get the sum of two int fields:

SELECT column_a, column_b, (column_a + column_b) as total FROM tablename

However, looking at your other questions, I'm not sure whether mySQL is really what you are looking for. It sounds to me like you need an application just like Excel.

like image 190
Pekka Avatar answered Sep 25 '22 12:09

Pekka