Код: Выделить всё
CREATE TABLE VAL_DATE (
ID INTEGER NOT NULL,
ID_OBJ INTEGER NOT NULL,
ID_PARAM INTEGER NOT NULL,
VAL TIMESTAMP
);
CREATE TABLE VAL_TIME (
ID INTEGER NOT NULL,
ID_OBJ INTEGER NOT NULL,
ID_PARAM INTEGER NOT NULL,
VAL TIME
);
Нужно определить ID записи для ближайшей меньшей даты
Написал я запрос:
Код: Выделить всё
select rd.id, max (cast(rd.val as date) + cast(rt.val as time ) ) ts
from val_date rd left join val_time rt on (Rt.id = rd.id)
where (rd.id_obj = 148) and (rd.id_param = 5) and (Rt.id_param =7)
and ((cast(rd.val as date) + cast(rt.val as time )) <= '11.10.07 18:15:00')
group by 1
having max(cast(rd.val as date) + cast(rt.val as time ))=
(select max (cast(rd1.val as date) + cast(rt1.val as time ) )
from val_date rd1 left join val_time rt1 on (Rt1.id = rd1.id)
where (rd1.id_obj = 148) and (rd1.id_param = 5) and (Rt1.id_param =7)
and ((cast(rd1.val as date) + cast(rt1.val as time )) <= '11.10.07 18:15:00'))
Может кто подскажет как?