Can I enter formula in the column for MySQL database?
I wonder if the above can operate the column like the excel.
eg. s开发者_运维百科ame row. column 1 : A, column 2 : b, column 3 : A + b.
It doesn't look like MySQL supports computed columns as per SQL Server.
You could use a View with these calculated columns in or (if you want the value of the calculation to be persisted so you can search against it using an index) add a column and keep it up-to-date with triggers
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.
you can create a view of the table like you mention
like :
create view myview as select a,b,(a+b) as c from table
mysql is a database and not a spreadsheet so no you can't, and you probably shouldn't be anyway.
I suppose the point is that a spread sheet holds AND displays the data - mysql holds the data then you use php to show the data (or similar).
When you retrieve from the database you can do:
SELECT (A+B) AS c FROM table
or when you put into the database you can do the maths.
I come from an Excel background myself and found that to be one of the challenges of moving over to databases, but I realize now that data is rarely presented as-is from a table. Chances are you will be using a view because you or your end users will want to see it laid out a certain way.
Pretty much any time you think you want a calculated field, chances are you would do well to create a view that performs the calculation. it also keeps the load off of any application you might be developing to use the info, because the calculations are done server-side.
- If you need the function of Excel but need it to store larger data sets using MySQL is fine. However, to get the calculated columns you need to use an interface and Microsoft makes one called Access. You can use Access to interact with your database and build queries to return your answers the way you want them.
This would keep you from having to build a web interface to your MySQL database to accomplish the same thing.
精彩评论