I have a problem with a subquery in MySQL that runs in query timeout:
SELECT mac fROM cc_btdata where date (time) = "2014-09-29" and not mac (Mac to Mac CC-Boineda where between date (time) ("2014-09-29" - interval 60 days) and ("2014 -09-29 "- Interval 1 day) by Mac group) Mac
When I call from one to one it works but when I do not call them as subcure Does I have also tried questions in MariDiBi in my development environment and it works but not in MySQL.
What's wrong with this question?
Thank you!
You can type a query like this:
Select from Mac cc_btdata b where not present (SELECT 1 to cc_btdata b2 WHERE bmc = b 2.mac and time & gt; = '2014-09-29' - INTERVAL 60 days and time & lt; '2014-09- 29 '- INTERVAL 1 day) and Time & gt; = '2014-09-29' and time & lt; '2014-09-29' + Interval 1 day;
For display, you want an index at cc_btdata (mac, time)
. I rewrite the date comparison without the date ()
, so MySQL will be able to take advantage of the index.
You can also write it as:
Selectfrom where time & gt; = '2014-09-29' - INVAL 60 Days to be a group MAC (date (time) = '2014-09-29') & gt; 0 and the amount ('2014-09-29' between date (time) - interval 60 days and '2014-09-29' - interval 1 day) = 0;
(I used the original expression for the ones
section because MySQL can not take advantage of the indexes for the section
. ) The first version probably has a better performance.
Comments
Post a Comment