如何在Presto中使用二进制表示法写整数?

时间:2018-07-31 21:33:05

标签: presto

在使用grouping(与grouping sets一起使用时,有什么方法可以使用二进制表示法写整数吗?

例如,我想写

select
    case grouping(A, B, C, D)
        when 0x0011 then 'ONLY AB'  -- 
        when 0x0101 then 'ONLY AC'
        else 'ABCD'
    end as label,

    count(*) as statements,
from T
group by grouping sets ((A, B, C), (A, B), (A, C), (A))

代替

select
    case grouping(A, B, C, D)
        when 3 then 'ONLY AB'
        when 5 then 'ONLY BD'
        else 'ABCD'
    end as label,

    count(*) as statements,
from T
group by grouping sets ((A, B, C), (A, B), (A, C), (B, D), (A))

1 个答案:

答案 0 :(得分:3)

Presto不支持base-2文字,但是您可以使用from_base

SELECT from_base('1101', 2);