Как использовать диапазоны с Presto DB - PullRequest
0 голосов
/ 14 декабря 2018

Я хочу сделать следующее, что я нашел для SQL Server , используя PrestoDB?

select t.range as 'latency', count(*) as 'Total'
from (
  select case  
    when latency between 0 and 0.250 then 'Fast'
    when latency between 0.250 and 1.0 then 'Normal'
    when latency between 1.0 and 2.0 then 'Elevated'
    else 'High' 
  end as range
  from myprestodb.mytable) t
group by t.range

... так, чтобы я получил такой результат:

latency        | Total
-------------------------------------
   Fast        |        11
   Normal      |        14
   Elevated    |         3
   High        |         1

Ответы [ 2 ]

0 голосов
/ 17 декабря 2018

Вы можете использовать count_if, чтобы предоставить условия для того, что подсчитывается для каждого столбца.Это было именно то, что я искал:

select count_if(latency < 0.25) as "Fast: < .25", 
    count_if(latency > 0.25 and latency <= 1.0) as "Normal: .25 - 1", 
    count_if(latency > 1.0 and latency <= 2.0) as "Elevated: 1 - 2", 
    count_if(latency > 2.0) as "High: > 2"

from myprestodb.mytable
...
0 голосов
/ 14 декабря 2018

Вы можете попробовать:

select range as Latency, count(*) as Total
from (
  select case  
    when latency > 0 and latency <= 0.250 then 'Fast'
    when latency > 0.250 and latency <= 1.0 then 'Normal'
    when latency > 1.0 and latency <= 2.0 then 'Elevated'
    else 'High' 
  end as range
  from myprestodb.mytable
)
group by range
...