<p>Let's say that I want to have a table that logs the date and the number of columns in some other table (or really any sort of math / string concat etc).</p>

<pre><code>CREATE TABLE `log` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`date` DATETIME NOT NULL ,
`count` INTEGER NOT NULL ,
PRIMARY KEY (`id`)
);
</code></pre>

<p>Is it possible to have the count column calculated for me whenever I do an insert?</p>

<p>e.g. do something like:</p>

<pre><code>INSERT INTO log (date='foo');
</code></pre>

<p>and have count calculated by mysql.</p>

<p>Obviously I could do it myself by doing a query to get the count and inserting it, but this would be better.</p>

You definitly have to declare what to insert. This should be possible by using the
INSERT ... SELECT
statement.
```
```
INSERT INTO log (date, count)
    SELECT DATE() as date, count(id) as count
    from foo;
```
```
Which should insert a new row into the log table, containing todays date and the number of  rows in the foo table. (Assuming the foo table has an id column.. Use the primary key or another indexed column)