Código PHP:
select country, count(provider_id)as total
from provider group by country order by total DESC Limit 5

Quiero que el resultado sea este:

Como se puede hacer? Esto si sería sofisticado para mí...
Gracias de Antemano.
| ||||
Código:
Espero que te sirva select country, count(provider_id)as total from provider group by country order by total DESC Limit 5 UNION Select 'otros' as country, count(provider_id) as total from provider where provider_id not in (select provider_id from provider group by country order by total DESC Limit 5 ) |
| ||||
Puedes hacer 2 cosas, 1- Actualizar la versión de MySQL (a 4.18 estable) o 2- Intentar esto (aunque no se si te lo cojera) [CODE] select country, count(provider_id)as total from provider group by country order by total DESC Limit 5 UNION Select 'otros' as country, count(provider_id) as total from provider Pro where not EXISTS (select provider_id from provider where provider_id=Pro.provider_id group by country order by total DESC Limit 5 ) [CODE] Creo recordar que era así la sintaxis, es que hace mucho que no uso el NOT EXISTS, puesto que es más complicado. Un saludo |
| ||||
Pues como no te coja esto, (esta me ha funcionado a mi)
Código:
(select country, count(provider_id)as total from provider group by country order by total DESC Limit 5) UNION (Select 'otros' as country, count(provider_id) as total from provider where not EXISTS (select country, count(provider_id)as total from provider group by country order by total DESC Limit 5)) |
| ||||
Ah bueno, lo he colocado en una página y la consulta sale, lo que ha de ocurr¡r es una excepción porque estoy utilizando el Mysql Front 2,5 con Mysql 4.1.9 Qué otro manejador gráfico para versiones de mysql superiores me recomendais? En phpmyadmin 2.6.1 también sale un error. Como lo has probado tu? En la pagina que si ejecuta la consulta sale la suma como 0 cero. |
| ||||
prueba con lo siguiente
Código:
(select country, count(provider_id) as total from provider group by country order by total DESC Limit 5) UNION (Select 'otros' as country, count(provider_id) as total from provider where not EXISTS (select country from provider group by country order by count(provider_id) DESC Limit 5))
__________________ Bien se puede recibir una puñalada sin adulación, pero rara vez se recibe una adulación sin puñalada ** *** |
| ||||
Cita:
Iniciado por Linterns prueba con lo siguiente
Código:
(select country, count(provider_id) as total from provider group by country order by total DESC Limit 5) UNION (Select 'otros' as country, count(provider_id) as total from provider where not EXISTS (select country from provider group by country order by count(provider_id) DESC Limit 5)) Gracias pero no funciona: Código PHP: |
| ||||
Prueba de esta manera Código PHP: ![]() |