Доброго времени суток....
Есть запрос на выборку данных...в таблице на данный момент пока только 1500 записей...запрос выглядит так:
SELECT DISTINCT
spr_otdelenie.otdelenie_name,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-01-01 00:00:00')) and (concat(p_year,'-01-31 23:59:59'))) ) as january,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-02-01 00:00:00')) and (concat(p_year,'-02-29 23:59:59'))) ) as february,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-03-01 00:00:00')) and (concat(p_year,'-03-31 23:59:59'))) ) as march,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-04-01 00:00:00')) and (concat(p_year,'-04-30 23:59:59'))) ) as april,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-05-01 00:00:00')) and (concat(p_year,'-05-31 23:59:59'))) ) as may,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-06-01 00:00:00')) and (concat(p_year,'-06-30 23:59:59'))) ) as june,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-07-01 00:00:00')) and (concat(p_year,'-07-31 23:59:59'))) ) as july,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-08-01 00:00:00')) and (concat(p_year,'-08-31 23:59:59'))) ) as august,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-09-01 00:00:00')) and (concat(p_year,'-09-30 23:59:59'))) ) as september,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-10-01 00:00:00')) and (concat(p_year,'-10-31 23:59:59'))) ) as october,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-11-01 00:00:00')) and (concat(p_year,'-11-30 23:59:59'))) ) as november,
(select count(*) from nakladnie_comp
where (nakladnie_comp.status=1) and (nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie) and (nakladnie_comp.date_reg_status between (concat(p_year,'-12-01 00:00:00')) and (concat(p_year,'-12-31 23:59:59'))) ) as december
from nakladnie_comp inner Join spr_otdelenie ON nakladnie_comp.spr_otdelenie_id = spr_otdelenie.id_spr_otdelenie;
выполняется запрос 6 сек.....скажите это нормально...или можно оптимизировать чтобы выполнялся быстрее????
заранее спасибо ))