Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/12/2009, 11:14
jurena
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Cáceres
Mensajes: 3.735
Antigüedad: 17 años
Puntos: 300
Respuesta: Subconsulta con case y ALias

Esta es una posible solución (he usado IF en lugar de when case):
SELECT SUM(IF(timestampdiff(year,Fecha_nacimiento,curdate ()) between 0 and 5,1,0)) 'pacientes entre 0 y 5', SUM(IF(timestampdiff(year,Fecha_nacimiento,curdate ()) between 6 and 10,1,0)) 'pacientes entre 6 y 10', SUM(IF(timestampdiff(year,Fecha_nacimiento,curdate ()) between 11 and 15,1,0)) 'pacientes entre 11 y 15', SUM(IF(timestampdiff(year,Fecha_nacimiento,curdate ()) between 16 and 20,1,0)) 'pacientes entre 16 y 20', SUM(IF(timestampdiff(year,Fecha_nacimiento,curdate ()) > 20,1,0)) 'pacientes mayores de 20' from galenvs.paciente