My Mysql table looks like this currently:
| id | time |
|---|---|
| 1 | 2011-12-12 09:27:24 |
| 1 | 2011-12-13 09:27:31 |
| 1 | 2011-12-14 09:27:34 |
| 2 | 2011-12-14 09:28:21 |
and I would like to add a virtual generated column returning a boolean. This boolean would be true if it is the most recent entry for a given id.
| id | time | is_last_entry |
|---|---|---|
| 1 | 2011-12-12 09:27:24 | 0 |
| 1 | 2011-12-13 09:27:31 | 0 |
| 1 | 2011-12-14 09:27:34 | 1 |
| 2 | 2011-12-14 09:28:21 | 1 |
How should I write this statement?
CREATE TABLE test(
id INT NOT NULL,
time DATETIME NOT NULL,
is_last_entry TINYINT GENERATED ALWAYS AS [=> please complete here]
);