Помогите пожалуйста упростить такой запрос. Нужно выбрать количество предприятий с одной таблици с разными условиями Вот такой запрос сильно грузит страницу! [sql]select st0.status0 AS st0, st1.status1 AS st1, st2.status2 AS st2, st3.status3 AS st3, st4.status4 AS st4, st5.status5 AS st5, st6.status6 AS st6 , st7.status7 AS st7, st8.status8 AS st8, st9.status9 AS st9, st10.status10 AS st10, st11.status11 AS st11, st12.status12 AS st12, st13.status13 AS st13, st14.status14 AS st14, st15.status15 AS st15, st16.status16 AS st16, st17.status17 AS st17, st18.status18 AS st18, st19.status19 AS st19, st20.status20 AS st20 from (select count(Num) as status0 from `clients` where `manager`='$ID' AND `status`=0) st0, (select count(Num) as status1 from `clients` where `manager`='$ID' AND `status`=1) st1, (select count(Num) as status2 from `clients` where `manager`='$ID' AND `status`=2) st2, (select count(Num) as status3 from `clients` where `manager`='$ID' AND `status`=3) st3, (select count(Num) as status4 from `clients` where `manager`='$ID' AND `status`=4) st4, (select count(Num) as status5 from `clients` where `manager`='$ID' AND `status`=5) st5, (select count(Num) as status6 from `clients` where `manager`='$ID' AND date=now() AND (`status`=0 OR `status`=1 OR (`status`='5' AND `from`='-5'))) st6, (select count(Num) as status7 from `clients` where `manager`='$ID' AND `ver`=1) st7, (select count(Num) as status8 from `clients` where `manager`='$ID' AND `ver`=0) st8, (select count(Num) as status9 from `clients` where `manager`='$ID' AND `status`=5 AND (`from`='-1' )) st9, (select count(Num) as status10 from `clients` where `manager`='$ID' AND `status`=5 AND `from`='-2') st10, (select count(Num) as status11 from `clients` where `manager`='$ID' AND `status`=5 AND `from`>0) st11, (select count(Num) as status12 from `clients` where `manager`='$ID' AND `status`=5 AND `from`='-4') st12, (select count(Num) as status13 from `clients` where `manager`='$ID' AND `status`=5 AND `date`=NOW()) st13, (select count(Num) as status14 from `clients` where `manager`='$ID' AND `status`=5 AND (`from`='-1' OR `from`=0) AND `date`=NOW()) st14, (select count(Num) as status15 from `clients` where `manager`='$ID' AND `status`=5 AND `from`='-2' AND `date`=NOW()) st15, (select count(Num) as status20 from `clients` where `manager`='$ID' AND `status`=5 AND `from`='-5') st20, (select count(Num) as status16 from `clients` where `manager`='$ID' AND `status`=5 AND `from`>0 AND `date`=NOW()) st16, (select count(Num) as status17 from `clients` where `manager`='$ID' AND `status`=5 AND `from`='-4' AND `date`=NOW()) st17, (select count(Num) as status18 from `clients` where `manager`='$ID' AND `status`=3 AND `ver`=1) st18, (select count(Num) as status19 from `clients` where `manager`='$ID' AND `status`=3 AND `ver`=0) st19 $rez=mysql_query($sql) or die (mysql_error());[/sql]
Упростить особо не получится, но вот сделать что-бы не так страшно было - можно. Сделайте 19 запросов с разными условиями. Так базе будет легче и проще отладить с индексами.
как вариант, решение в 2 запроса: [sql] select sum(status0), sum(status5) from( select if(status=0,1,0) status0 if(status =5 AND from=-1,1,0) status5 from clients where manager=$ID) t [/sql] правда тут будут выбираться все записи, с manager=$ID, так что неизвестно еще, что будет выполняться дольше