Создаю view
Код: Выделить всё
recreate view test
(ID, EventCode, EventDate, EventLength, RestDate)
as
select
ID,
EventCode,
EventDate,
EventLength,
iif(EventCode < 0, rdb$set_context('USER_SESSION', 'rest' || ID,
EventDate), rdb$get_context('USER_SESSION', 'rest' || ID))
from vDrivers2
where not (EventCode<0 and EventLength < 9.0/24)
1.
Код: Выделить всё
select EventLength, RestDate from Test
Код: Выделить всё
EVENTLENGTH RESTDATE
34.046162836 0
28.000127141 0
9.186792707 2007-01-30 08:32:14.5310
0.012951389 2007-02-06 17:25:30.0150
6.458831019 1
0.041805556 2007-03-06 17:44:20.0000
0.042465278 2007-03-06 17:44:20.0000
0.38318287 1
0.289571759 2007-03-13 14:37:16.0000
0.189907407 2007-03-13 14:37:16.0000
0.163449074 2007-03-13 14:37:16.0000
Код: Выделить всё
select RestDate, Sum(EventLength)
from Test
group by RestDate
Код: Выделить всё
RESTDATE SUM
1 68.888303866
2007-01-30 08:32:14.5310 9.186793065
2007-03-13 14:37:16.0000 0.740150463
Помогите разобраться, пожалуйста!