When I run a medium complex query with one inner join (and 2 unions), data returns in under 5s, 483 rows. One of the key pieces of info is "Days Between" (the end of one trip and the beginning of another). (The entire data set is small, as are the base tables)
But when I query the whole thing and say "where days_between_trips between -10 and 10", the query never returns !
The problem is a person taking four trips with a short break between trips, trying to get days_between each trip.
So this works great, 483 rows, neat and tidy
select Trip #, Trip_Info, Next_Trip_Info, days_between from (
select Trip_#, Trip_1_Info, Trip_2_Info,
date_2_start - date_1_end as days_between
from table_1_vw a
inner join table_2_vw b on a.user_id = b.user_id
select Trip_#, Trip_2_Info, Trip_3_Info,
date_3_start - date_2_end as days_between
from table_2_vw b
inner join table_3_vw c on b.user_id = c.user_id
select Trip_#, Trip_3_Info, Trip_4_Info,
date_4_start - date_3_end as days_between
from table_3_vw c
inner join table_4_vw d on d.user_id = c.user_id
where trip_year = [current_year]
and trip_status = 'ACTIVE
but when I add
*** --> "and days_between between -10 and 10", the query never returns.
I figured the data would be pulled into memory (483 rows) and then it's a simple matter to take this and filter out those rows not meeting the days_between criteria.
Why am I seeing this scenario ?
It's a enterprise system, everything seems good, etc.