我有两个庞大的表,每个表查询大约需要1分钟,这是可以接受的。 我想做的就是这个..
表1
job | profile_value | type
-------------------------------------------
job1 | p1 | order
job2 | p1 | order
job3 | p3 | order
table2
job_no | profile_no | status
-------------------------------------------
job1 | p1 | completed
job2 | p2 | completed
job3 | p3 | finished
job4 | p3 | started
基本上job2在这里是不同的。此查询绝对不好,因为它进行了蛮力比较。
SELECT A.jobuuid
FROM (
select job as job_id, profile_value as profile_id
from table1
CROSS JOIN ....
where type = 'order' and datestr >= '{{min_date}}'
) AS A
JOIN (
SELECT job_no as job_id, profile_no as profile_no as profile_id
FROM table2
CROSS JOIN ....
WHERE datestr >= '{{min_date}}' AND status IN ('completed', 'finished')
) AS B
ON A.profile_id != B.profile_id AND A.job_id=B.job_id
查询应获取不同步的查询的数量...
输出:
job_id | profile_id
--------------------------
job2 | p2 (Since the job_ids are same and profile_id is diff)