· 8 years ago · Jan 30, 2018, 07:28 AM
1CREATE TABLE IF NOT EXISTS devices(
2 device_id serial PRIMARY KEY,
3 device_name varchar(255) UNIQUE NOT NULL,
4 last_record_time timestamp without time zone NOT NULL DEFAULT '1995-10-30 10:30:00'
5);
6
7CREATE TABLE IF NOT EXISTS temperature(
8 device_id integer NOT NULL,
9 temperature decimal NOT NULL,
10 record_time timestamp without time zone,
11 CONSTRAINT temperature_device_id_fkey FOREIGN KEY (device_id)
12 REFERENCES devices (device_id) MATCH SIMPLE
13 ON UPDATE NO ACTION ON DELETE NO ACTION
14);
15
16SELECT MAX(record_time) FROM temperature WHERE device_id=4;