-1

I'm trying to run two MySQL queries on tables with no matching columns. The results of these two queries need to be matched up and present information only if a portion of one column matches a column from the other database. Here is what I have so far:

select data2, time_id from db.table1
where data2 in
(select right(dst,10) from db2.table2
where calldate like '2012-09-01%' and lastdata like <blocked for privacy>)
having (time_id between '1346475600' and '1346562000');

In my understanding, the subquery on lines 3-4 should be called first, correct? My issue with this statement is that it always times out. It just takes too long. Am I formatting this incorrectly? I'm sure an alternative would be to use a join statement, and any help in that direction would be great.

4

1 回答 1

0

你没有错误地格式化它,这只是一个非常糟糕的查询,需要服务器进行一些荒谬的计算。让我们采取一些步骤把它做好,真的只是一件大事和一件小事。

  1. 不要尝试加入部分字段。向 table2 添加一列,该列将包含要加入的数据。运行查询以填充该字段。添加触发器以使该字段保持最新。不允许提醒架构?创建一个临时表并相应地填充它并加入它。
  2. 不要在日期时间字段上使用like,call date BETWEEN <datetime 1> AND <datetime 2>而是说。
于 2012-09-11T22:02:43.240 回答