Tengo el sgte código
Código PHP:
   $select = "select c.codigo, count(*) as veces, c.nombre, c.direccion from comercios c, problemas p";
$select.= " , detproblemas d, h_desk h where h.idprob = p.idprob and h.probid = d.probid and h.idcomercio = c.idcomercio";
if($lswhere!=""){$select .= " and ".$lswhere;}
$select .= " group by codigo order by veces desc"; 
    Código PHP:
   select c.codigo, count(*) as veces, c.nombre, c.direccion 
from comercios c, problemas p , detproblemas d, h_desk h 
where h.idprob = p.idprob and h.probid = d.probid 
and h.idcomercio = c.idcomercio and h.idprob = 4000 and h.probid = 44 
group by codigo 
order by veces desc
+--------+-------+------------------------------+----------------------------------------------------+
| codigo | veces | nombre                       | direccion                                          |
+--------+-------+------------------------------+----------------------------------------------------+
| 13601  |    35 | Farmacia San Carlos          | Av. Carlos Izaguirre 906                           |
| 13903  |    11 | Farmacia Virgen de la Merced | Av. Del Olmo 986                                   |
| 13908  |    10 | Botica San Pedro             | Av. Las Lomas 1565                                 |
+--------+-------+------------------------------+----------------------------------------------------+ 
    Datos:
Apache Web Server Version 1.3.33
PHP Script Language Version 4.3.9
MySQL Database Version 4.1.7
Zend Optimizer Version 2.5.5
Alguna ayuda por favor???
 
