mysql - Match Datetime entries against table with multiple time ranges -
i'm once more trying solve mysql related problem sounds simple @ first causing me headaches. i've read numerous snippets , experimented couple days alas have not had success in terms of finding perfect solution.
i have 2 tables. first 1 contains phone calls, each phone call represented row in first table, has following 3 columns:
p_key (int), call_date (date), call_time ( time )
my second table contains specific events, 3 columns:
event_id ( int ), event_start ( datetime ), event_end ( datetime )
i count entries first table - call table - not fall within time between start , end events table same date.
my main problem is, there may multiple entries in events table single date ( example: event 0800 - 1000 , 1 1400 1600 on same day ). otherwise use between syntax.
i imagine affect:
select sum( case when t1.p_key != 0 1 else 0 end ) brt, sum( case when t1.p_key != 0 , t1.call_time not between time(t2.event_start) , time(t2.event_end) 1 else 0 end ) net call_table t1 inner join event_table t2 on t1.call_date = date(t2.event_start) t1.call_date >= '2013-09-01' , t1.call_date <= '2013-09-30' group day(t1.call_date)
unfortunately query returns no results.
can point me rough direction ?
p.s. tried find reference on how format sample table data in posts here on so, either blind or there no specific reference. since i've seen nicely formatted example table data, know possible clue on appreciated lot well.
update managed output, using left join instead of inner. since no mysql expert, go , -cough- count hand if results correct.
you query should then
select timestamp(call_date, call_time) calls left join events on timestamp(call_date, call_time)>event_start , timestamp(call_date, call_time)<event_end event_start null
-see fiddle.
for result in count, do
select count(calls.id) calls left join events on timestamp(call_date, call_time)>event_start , timestamp(call_date, call_time)<event_end event_start null
Comments
Post a Comment