Is it possible to have a mysql database automatically fill a column based on the results from two other columns.

eg. Column 1: Points
Column 2: Matches
Column 3: Average

Is it possible to have the value in the 'Points' column divide by the value in the 'Matches' column and fill the result in the 'Average' column?

I know this can be done in php but was wondering if it's possible to have it done in the database?

    Pretty sure I answered this in the other thread....😛

      Heres the jist. Databases are storage devices only (software really). They just do what they do. It is the procedures that you write that perform functions.

        Mysql (and SQL in general I suppose) have a multitude of functions for doing basic data processing, such as summing and formatting etc. Some of them are pretty powerful. You can do this entirely using an SQL statement.

          khendar, you are write in general, but don't lead them on. An inline calculation with the query is still a written procedure. The database will not do it.

          $sql = "SELECT * FROM table WHERE postdate <= ".(time()-3600)." ";

            You are talking about using a php function within a query string. Thats not what I am referring to. MySQL is able to divide the values in fields within the query - I just tested it in phpmyadmin. Try it yourself.

            UPDATE table set value1 = 12, value2 = 3, value3 = value1/value2

            will set value3 = 4. Works fine.

              Write a Reply...