I have two inline views with start_time and end_time in each of them. Now I need to get the difference: end_time - start_time when end_time > max(start_time). Max(start_time) means the start_time right before the end_time.
Basically, what I need to do is:
update table a set column b =
(select case vu1.end_time > max(vu2.start_time)
then vu1.end_time - max(vu2.start_time)
else 0
end
from vu1, vu2)
where b is null;
The problem is this is not a single group function.
Any other way I can accomplish this?
Thanks!