views:

52

answers:

4

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.

+1  A: 

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
Haim Evgi
+2  A: 

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.

Pekka
:) guess I just have to keep trying. I dont think there is a application for 'like excel' + database. What do you think?
King
@King not entirely, that's true. But mySQL plus a graphical frontend like HeidiSQL (www.heidisql.com) can come close. Looking a second time at your other questions, and seeing that you *do* come from Excel, you may be on the right way after all!
Pekka
+1  A: 

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

Martin Smith
http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-views/ voted this answer after read the link. It make sense and flexible.
King
+1  A: 

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.

Thomas Clayson
If that was really true there would be no computed columns.
Hemal Pandya