编辑最终:修改后的代码适用于 5.5,但在 5.0 上,我得到的行集略有不同,任何人都有任何想法......
以下查询
SELECT DISTINCT
sql_no_cache as job.id,
job.id as job_id,
job.job_status,
job.servee_name,
kase.plaintiff,
index_number,
lawfirm_filenumber,
DATE_FORMAT(job.datetime_received, '%m/%d/%Y') as date_received,
DATE_FORMAT(job.date_sent_to_court, '%m/%d/%Y') as date_sent_to_court,
DATE_FORMAT(kase.date_kase_filed, '%m/%d/%Y') as date_kase_filed,
TO_DAYS(NOW())-TO_DAYS(kase.date_kase_filed) as thedays,
DATE_FORMAT(kase.court_datetime, '%m/%d/%Y %h:%i %p') as court_date,
kase.court_room,
CONCAT( LUcourt.court_county," - ",LUcourt.court_type) as court_name,
DATE_FORMAT( job.datetime_served, '%m/%d/%Y') as datetime_served,
CONCAT( server.namefirst,' ', server.namelast) as server_name
FROM job
LEFT JOIN kase ON job.kase_id = kase.id
LEFT JOIN kasebilling ON kasebilling.kase_id = kase.id
LEFT JOIN server ON job.server_id = server.id
LEFT JOIN client ON client.id = kase.client_id
LEFT JOIN LUcourt ON LUcourt.id = kase.court_id
WHERE job.subscriber_id = 1
ORDER BY job_id + 0
LIMIT 0,500;
</pre>
i modified the query but it wont run ...
SELECT DISTINCT sql_no_cache job.id, job.id as job_id, job.job_status, job.servee_name, kase.plaintiff, index_number, lawfirm_filenumber, DATE_FORMAT(job.datetime_received, '%m/%d/%Y') as date_received, DATE_FORMAT(job.date_sent_to_court, '%m/%d/%Y') as date_sent_to_court, DATE_FORMAT(kase.date_kase_filed, '%m/%d/%Y') as date_kase_filed, TO_DAYS(NOW())-TO_DAYS(kase.date_kase_filed) as thedays, DATE_FORMAT(kase.court_datetime, '%m/%d/%Y %h:%i %p') as court_date, kase.court_room, CONCAT(LUcourt.court_county," - ",LUcourt.court_type) as court_name, DATE_FORMAT(job.datetime_served, '%m/%d/%Y') as datetime_served, concat(server.namefirst,' ', server.namelast) as server_name FROM job
LEFT JOIN kase ON job.kase_id = kase.id
LEFT JOIN kasebilling ON kasebilling.kase_id = kase.id
LEFT JOIN server ON job.server_id = server.id
left join client on client.id=kase.client_id
left join LUcourt on LUcourt.id=kase.court_id WHERE job.subscriber_id = 1 and job_id in (select distinct job.id from job where job.subscriber_id = '1' order by id+0) LIMIT 0,500
</pre>
我已经修改了上面的查询以删除一些表名......但是发生的情况是,如果我通过查询删除订单会非常快......我认为它的排序不仅仅是限制 500,而是所有行...我怎样才能通过 order by 更快地完成这项工作。任何帮助将不胜感激谢谢....
PS:它在 order_by 上使用文件排序...
解释:
+----+-------------+-------------+--------+------- -------------------------------------------------- -----------------------------------------+-------- -------------------------+---------+-------------- ---------+--------+------------------------------- ---------------+ | 编号 | 选择类型 | 表| 类型 | 可能的键 | 关键 | key_len | 参考 | 行 | 额外 | +----+-------------+-------------+--------+------- -------------------------------------------------- -----------------------------------------+-------- -------------------------+---------+-------------- ---------+--------+------------------------------- ---------------+ | 1 | 简单 | 工作 | 参考 | 订阅者 ID,订阅者 ID-job_loc-client_loc-server_loc,sub_id_idx_servee_name_idx | subscriber_id-job_loc-client_loc-server_loc | 4 | 常量 | 362381 | 使用哪里;使用临时的;使用文件排序 | | 1 | 简单 | 加濑 | eq_ref | 初级 | 初级 | 4 | pserve.job.kase_id | 1 | | | 1 | 简单 | 卡西比林 | 参考 | kase_id | kase_id | 4 | pserve.kase.id | 2 | 使用索引 | | 1 | 简单 | 服务器 | eq_ref | 初级 | 初级 | 4 | pserve.job.server_id | 1 | | | 1 | 简单 | 客户 | eq_ref | 初级 | 初级 | 4 | pserve.kase.client_id | 1 | 使用索引 | | 1 | 简单 | 卢考特 | eq_ref | 初级 | 初级 | 4 | pserve.kase.court_id | 1 | | +----+-------------+-------------+--------+------- -------------------------------------------------- -----------------------------------------+-------- -------------------------+---------+-------------- ---------+--------+------------------------------- ---------------+
我修改了查询,但它不会运行...
SELECT DISTINCT sql_no_cache job.id, job.id as job_id, job.job_status, job.servee_name, kase.plaintiff, index_number, lawfirm_filenumber, DATE_FORMAT(job.datetime_received, '%m/%d/%Y') as date_received, DATE_FORMAT(job.date_sent_to_court, '%m/%d/%Y') as date_sent_to_court, DATE_FORMAT(kase.date_kase_filed, '%m/%d/%Y') as date_kase_filed, TO_DAYS(NOW())-TO_DAYS(kase.date_kase_filed) as thedays, DATE_FORMAT(kase.court_datetime, '%m/%d/%Y %h:%i %p') as court_date, kase.court_room, CONCAT(LUcourt.court_county," - ",LUcourt.court_type) as court_name, DATE_FORMAT(job.datetime_served, '%m/%d/%Y') as datetime_served, concat(server.namefirst,' ', server.namelast) as server_name FROM job
LEFT JOIN kase ON job.kase_id = kase.id
LEFT JOIN kasebilling ON kasebilling.kase_id = kase.id
LEFT JOIN server ON job.server_id = server.id
left join client on client.id=kase.client_id
left join LUcourt on LUcourt.id=kase.court_id WHERE job.subscriber_id = 1 and job_id in (select distinct job.id from job where job.subscriber_id = '1' order by id+0) LIMIT 0,500