我有两个 sql 表,alarmMessage
并且coordinates
. alarmMessage
表具有表的外键字段coordinates
。alarmMessage
我想从其坐标具有最新(最大)gpsDate 字段的表中检索单行。
报警信息:
CREATE TABLE alarmmessage
(
alarmmessageid bigint NOT NULL,
mtstrackid character varying(40),
coordinatesid bigint,
totaldistance double precision,
iostatusid bigint,
alarmstatus character varying(10),
totalworkingduration integer,
maintenanceremainingtime integer,
isread boolean NOT NULL DEFAULT false,
CONSTRAINT pk_alarmmessageid PRIMARY KEY (alarmmessageid ),
CONSTRAINT fk_coordinatesid FOREIGN KEY (coordinatesid)
REFERENCES coordinates (coordinatesid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_iostatus FOREIGN KEY (iostatusid)
REFERENCES iostatus (iostatusid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_mtstrackid FOREIGN KEY (mtstrackid)
REFERENCES vehicle (mtstrackid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
坐标:
CREATE TABLE coordinates
(
coordinatesid bigint NOT NULL,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
gpsvalid boolean,
gpsdate timestamp without time zone,
bearingangle double precision,
speed double precision,
mtstrackid character varying(40),
altitude double precision,
CONSTRAINT pk_coordinates PRIMARY KEY (coordinatesid )
)