sql >> Base de Datos >  >> RDS >> PostgreSQL

consulta sql que agrupa diferentes elementos en cubos

Una opción ampliada de lo que describió Kerrek, puede agrupar según un caso/cuándo

select
      case when price >= 0 and price <= 10    then '  0 - 10'
           when price > 10 and price <= 50   then ' 10+ - 50'
           when price > 50 and price <= 100  then ' 50+ - 100'
           else 'over 100'
      end PriceRange,
      count(*) as TotalWithinRange
   from
      YourTable
   group by 1

Aquí, el "grupo por 1" representa la columna ordinal en su instrucción de selección... en este caso, el caso/cuándo como TotalDentrodelRango.