如何在 Presto DB 中使用范围
How do I use ranges with Presto DB
我想使用 PrestoDB found for SQL Server 执行以下操作?
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
你可以试试:
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
您可以使用 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
...
我想使用 PrestoDB found for SQL Server 执行以下操作?
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
你可以试试:
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
您可以使用 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
...