Tomá, mirá como se simplifica la vida
Código SQL:
Ver originalSELECT
(SELECT COUNT(*) FROM medios WHERE medio LIKE 'face%')/COUNT(*) AS 'porcentaje facebook',
(SELECT COUNT(*) FROM medios WHERE medio LIKE 'twi%')/COUNT(*) AS 'porcentaje twitter'
FROM medios;
resultado:
Cita: mysql> select
-> (select count(*) from medios where medio like 'face%')/count(*) as 'porcentaje facebook',
-> (select count(*) from medios where medio like 'twi%')/count(*) as 'porcentaje twitter'
-> from medios;
+---------------------+--------------------+
| porcentaje facebook | porcentaje twitter |
+---------------------+--------------------+
| 0.7500 | 0.2500 |
+---------------------+--------------------+
1 row in set (0.00 sec)
si queres podes multiplicarlos *100