我有 BQ 表,其中有范围列。值类似于(0-50, 100-150, 200-250,1000-1200, >=400)
。
当我在此列上执行 orderBy 时,我得到的字典顺序如下 (0-50,100-150,1000-1200,200-250,>=400)
但我希望它按数字排序,例如(0-50,100-150, 200-250, >=400, 1000-1200)。
有人可以帮助我如何为此创建查询吗?
最佳答案
您可以使用以下示例中的方法
#standardSQL
with data as (
select '0-50' range_col union all
select '100-150' union all
select '200-250' union all
select '1000-1200' union all
select '>=400'
)
select *
from data
order by cast(regexp_extract(range_col, r'\b(\d+)\b') as int64)
带输出
关于google-bigquery - 按范围列排序(字符串类型)数字 BigQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64287319/