Friday, 15 April 2011

mysql - SQL Check from multiple tables if datetime is within 48 hours -



mysql - SQL Check from multiple tables if datetime is within 48 hours -

i have sql query:

select t.contact_name contact_name, t.contact_email contact_email, t.ticketnumber ticketnumber, t.subject subject tickets t bring together ticket_updates tu on t.ticketnumber = tu.ticketnumber tu.type = 'update' , t.status = 'awaiting customer' , tu.datetime <= '2014-10-27 11:18:19' grouping tu.ticketnumber order tu.datetime desc limit 0,1

which should shows records tickets when latest row in ticket_updates more 48 hours ago

i want able automatically alter status in tickets if there has been nil added in ticket_updates within 48 hours

in ticket_updates have 3 rows next datetime:

2014-11-22 00:00:00 2014-10-26 00:00:00 2014-10-28 00:00:00

so lastly 1 within 48 hours showing result on above query when shouldn't

you can inner select (not tested):

select t.contact_name contact_name, t.contact_email contact_email, t.ticketnumber ticketnumber, t.subject subject tickets t bring together ticket_updates tu on t.ticketnumber = tu.ticketnumber t.status = 'awaiting customer' , t.ticketnumber not in ( -- returns ticketnumbers have recent updates select recentupdates.ticketnumber ticket_updates recentupdates recentupdates.type = 'update' , recentupdates.datetime => '2014-10-27 11:18:19' ) grouping tu.ticketnumber order tu.datetime desc limit 0,1;

mysql sql

No comments:

Post a Comment