我正在开发一个可以生成不同格式的摘要报告的分发系统。我已经使用子查询来获取不同标准中特定列值的总和。使用子查询减慢了生成结果。我想知道有什么方法可以加快我的查询速度吗?或者我如何优化我的查询?这是我的询问。
SELECT
ar.area_name,
wk.workshop_name,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no like 'TE%'
and date_edit = '2014-02-13')
group by wk.workshop_name) as normal_tata_daily,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no like 'TE%'
and (date(date_edit) between '2014-02-01' and '2014-02-13'))
group by wk.workshop_name) as normal_tata_commulative,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no like 'TE%'
and (date(date_edit) between '2013-04-01' and '2014-03-01'))
group by wk.workshop_name) as normal_tata_overall,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no not like 'TE%'
and date_edit = '2014-02-13')
group by wk.workshop_name) as normal_non_tata_daily,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no not like 'TE%'
and (date(date_edit) between '2014-02-01' and '2014-02-13'))
group by wk.workshop_name) as normal_non_tata_commulative,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no not like '000W%'
and part_no not like 'TE%'
and (date(date_edit) between '2013-04-01' and '2014-03-01'))
group by wk.workshop_name) as normal_non_tata_overall,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no like 'TE%'
and date_edit = '2014-02-13')
group by wk.workshop_name) as warrenty_tata_daily,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no like 'TE%'
and (date(date_edit) between '2014-02-01' and '2014-02-13'))
group by wk.workshop_name) as warrenty_tata_commulative,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no like 'TE%'
and (date(date_edit) between '2013-04-01' and '2014-03-01'))
group by wk.workshop_name) as warrenty_tata_overall,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no not like 'TE%'
and date_edit = '2014-02-13')
group by wk.workshop_name) as warrenty_non_tata_daily,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no not like 'TE%'
and (date(date_edit) between '2014-02-01' and '2014-02-13'))
group by wk.workshop_name) as warrenty_non_tata_commulative,
(select
round(sum(selling_val), 2) as total
from
tbl_all_sales
where
(area_id = ar.area_id
and de = wk.identifier
and status = 1
and acc_no like '000W%'
and part_no not like 'TE%'
and (date(date_edit) between '2013-04-01' and '2014-03-01'))
group by wk.workshop_name) as warrenty_non_tata_overall
from
tbl_workshop wk
inner join
tbl_area ar ON wk.area_id = ar.area_id
left join
tbl_all_sales als ON ar.area_id = als.area_id
group by wk.workshop_name
order by ar.area_name
完全谢谢你的任何明智答案..