mysql> SELECT SUM(case when calltransactiontype='01' AND inservicekey IN (11,25) THEN callduration END)/60 as min_moc_prepago, SUM(case when calltransactiontype='01' AND inFlag IS NULL THEN callduration END)/60 as min_moc_pospago, SUM(case when calltransactiontype='02' THEN callduration END)/60 as min_entrante -> FROM cdr_20070510 -> WHERE calltransactiontype IN ('01','02') AND NOT (tgrpnameog like '_IP%' AND (dialledotherpartyb!='a600' AND dialledotherpartyb!='a666')) AND NOT(calltransactiontype='02' AND (dialledotherpartyb regexp '^30[01234]' OR dialledotherpartyb regexp '^5730[01234]')) -> ; +-----------------+-----------------+--------------+ | min_moc_prepago | min_moc_pospago | min_entrante | +-----------------+-----------------+--------------+ | 5590123.0167 | 3097814.6167 | 2219658.0000 | +-----------------+-----------------+--------------+ 1 row in set (2 min 18.30 sec) mysql> flush tables; Query OK, 0 rows affected (0.00 sec) mysql> flush query cache; Query OK, 0 rows affected (0.00 sec) mysql> SELECT SUM(case when calltransactiontype='01' AND inservicekey IN (11,25) THEN callduration END)/60 as min_moc_prepago, SUM(case when calltransactiontype='01' AND inFlag IS NULL THEN callduration END)/60 as min_moc_pospago, SUM(case when calltransactiontype='02' THEN callduration END)/60 as min_entrante -> FROM cdr_20070510 -> WHERE calltransactiontype IN ('01','02') AND IF(tgrpnameog like '_IP%' AND NOT (dialledotherpartyb='a600' OR dialledotherpartyb='a666'),0,1) AND IF(calltransactiontype='02' AND (dialledotherpartyb regexp '^30[01234]' OR dialledotherpartyb regexp '^5730[01234]'),0,1); +-----------------+-----------------+--------------+ | min_moc_prepago | min_moc_pospago | min_entrante | +-----------------+-----------------+--------------+ | 5590123.0167 | 3097814.6167 | 2219658.0000 | +-----------------+-----------------+--------------+ 1 row in set (43.43 sec) mysql> desc SELECT SUM(case when calltransactiontype='01' AND inservicekey IN (11,25) THEN callduration END)/60 as min_moc_prepago, SUM(case when calltransactiontype='01' AND inFlag IS NULL THEN callduration END)/60 as min_moc_pospago, SUM(case when calltransactiontype='02' THEN callduration END)/60 as min_entrante -> FROM cdr_20070510 -> WHERE calltransactiontype IN ('01','02') AND NOT (tgrpnameog like '_IP%' AND (dialledotherpartyb!='a600' AND dialledotherpartyb!='a666')) AND NOT(calltransactiontype='02' AND (dialledotherpartyb regexp '^30[01234]' OR dialledotherpartyb regexp '^5730[01234]')); +----+-------------+--------------+------+---------------------------------------------+------+---------+------+----------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+------+---------------------------------------------+------+---------+------+----------+-------------+ | 1 | SIMPLE | cdr_20070510 | ALL | ix_nombre_tabla_ctt,ix_nombre_tabla_dialled | NULL | NULL | NULL | 18068346 | Using where | +----+-------------+--------------+------+---------------------------------------------+------+---------+------+----------+-------------+ 1 row in set (0.00 sec) mysql> desc SELECT SUM(case when calltransactiontype='01' AND inservicekey IN (11,25) THEN callduration END)/60 as min_moc_prepago, SUM(case when calltransactiontype='01' AND inFlag IS NULL THEN callduration END)/60 as min_moc_pospago, SUM(case when calltransactiontype='02' THEN callduration END)/60 as min_entrante -> FROM cdr_20070510 -> WHERE calltransactiontype IN ('01','02') AND IF(tgrpnameog like '_IP%' AND NOT (dialledotherpartyb='a600' OR dialledotherpartyb='a666'),0,1) AND IF(calltransactiontype='02' AND (dialledotherpartyb regexp '^30[01234]' OR dialledotherpartyb regexp '^5730[01234]'),0,1); +----+-------------+--------------+------+---------------------+------+---------+------+----------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+------+---------------------+------+---------+------+----------+-------------+ | 1 | SIMPLE | cdr_20070510 | ALL | ix_nombre_tabla_ctt | NULL | NULL | NULL | 18068346 | Using where | +----+-------------+--------------+------+---------------------+------+---------+------+----------+-------------+ 1 row in set (0.00 sec)