I have this query here:
$query='insert into pageview (visitor,id_realestate,time)
select "q17872745t", 150, now()
from pageview a
where DATE_ADD(now(),INTERVAL -30 MINUTE) > (
select max(time) from pageview b where a.id_realestate=b.id_realestate AND a.visitor=b.visitor
) LIMIT 1';
I want this part:
select max(time) from pageview b where a.id_realestate=b.id_realestate AND a.visitor=b.visitor
to return a date/time which is now() minus 40 minutes if there are no results
Wrap the
MAX(time)in anIFNULLclause.