I have a table called "AGGREGATEVALUE" in a database schema "CLOUD". I'm using PostgreSQL:
CREATE TABLE CLOUD.AGGREGATEVALUE(
id SERIAL,
value CLOUD.FLOATVALUE NOT NULL,
idBoard VARCHAR(32),
idParameterRegolator VARCHAR(32),
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
FOREIGN KEY(idBoard) REFERENCES CLOUD.BOARD(id),
FOREIGN KEY(idParameterRegolator) REFERENCES CLOUD.PARAMETERREGOLATOR(id)
);
Here is an example of instance of this table (gained using a simple select for selecting all about idboard='board1'
)
id | value | idboard | idparameterregolator | timestamp
----+-------+---------+----------------------+----------------------------
1 | 1.00 | board1 | param1 | | 2014-08-24 10:29:33.677425
2 | 2.00 | board1 | param1 | | 2014-08-24 10:29:39.507868
3 | 4.00 | board1 | param1 | | 2014-08-24 10:29:46.286815
4 | 5.00 | board1 | param1 | | 2014-08-24 10:29:53.513363
5 | 1.00 | board1 | param2 | | 2014-08-24 10:29:58.252255
6 | 2.00 | board1 | param2 | | 2014-08-24 10:30:02.265151
7 | 3.00 | board1 | param2 | | 2014-08-24 10:30:05.480344
8 | 4.00 | board1 | param2 | | 2014-08-24 10:30:08.281917
9 | 5.00 | board1 | param2 | | 2014-08-24 10:30:10.845078
10 | 1.00 | board1 | param3 | | 2014-08-24 10:30:15.708794
11 | 2.00 | board1 | param3 | | 2014-08-24 10:30:18.82404
12 | 3.00 | board1 | param3 | | 2014-08-24 10:30:22.082542
13 | 4.00 | board1 | param3 | | 2014-08-24 10:30:24.662375
14 | 5.00 | board1 | param3 | | 2014-08-24 10:30:27.994689
Assuming by starting from the table above, what I need is to gain this other table:
value | idparameterregolator | timestamp
----------------------------------------------------------
5.00 | param1 | 2014-08-24 10:29:53.513363
5.00 | param2 | 2014-08-24 10:30:10.845078
5.00 | param3 | 2014-08-24 10:30:27.994689
That is, I need to gain for each parameter the corresponding value of the one with the last timestamp value.
I tried with ORDER BY
clause but without any results.