从 bigquery table 替换 'spaces'
replace 'spaces' from bigquery table
我有一个table
#standardSQL
with table as (
select 'DE' country, 520 number union all
select 'de' country, 480 number union all
select ' DE' country, 500 number union all
select ' DE ' country, 500 number
)
select replace(UPPER(country), ' ', '') as country_shop, number from table
GROUP BY country, number
我目前的结果看起来像
row country_shop number
1 DE 520
2 DE 480
3 DE 600
4 DE 400
我正在尝试将结果设为
row country_shop number
1 DE 2000
有人可以帮我吗?谢谢!
您正在尝试按 country_shop 和 number 列分组,但正如我们所见,这不是你想要的结果。您只想 group by
country_shop 和 sum
与该国家相关的所有号码。
太好了,您已经有了删除所有前导空格和尾随空格的函数 trim
和另一个名为 sum
的函数,然后您可以像这样构建查询:
select
upper(trim(country)) as country_shop,
sum(number) as total_number
from table
group by country_shop
请阅读包含 bigquery 已提供的所有功能的 following documentation 以找到适合您需要的功能。
改用下面的方法
#standardSQL
with table as (
select 'DE' country, 520 number union all
select 'de' country, 480 number union all
select ' DE' country, 500 number union all
select ' DE ' country, 500 number
)
select replace(UPPER(country), ' ', '') as country_shop, sum(number) number from table
GROUP BY country_shop
有输出
我有一个table
#standardSQL
with table as (
select 'DE' country, 520 number union all
select 'de' country, 480 number union all
select ' DE' country, 500 number union all
select ' DE ' country, 500 number
)
select replace(UPPER(country), ' ', '') as country_shop, number from table
GROUP BY country, number
我目前的结果看起来像
row country_shop number
1 DE 520
2 DE 480
3 DE 600
4 DE 400
我正在尝试将结果设为
row country_shop number
1 DE 2000
有人可以帮我吗?谢谢!
您正在尝试按 country_shop 和 number 列分组,但正如我们所见,这不是你想要的结果。您只想 group by
country_shop 和 sum
与该国家相关的所有号码。
太好了,您已经有了删除所有前导空格和尾随空格的函数 trim
和另一个名为 sum
的函数,然后您可以像这样构建查询:
select
upper(trim(country)) as country_shop,
sum(number) as total_number
from table
group by country_shop
请阅读包含 bigquery 已提供的所有功能的 following documentation 以找到适合您需要的功能。
改用下面的方法
#standardSQL
with table as (
select 'DE' country, 520 number union all
select 'de' country, 480 number union all
select ' DE' country, 500 number union all
select ' DE ' country, 500 number
)
select replace(UPPER(country), ' ', '') as country_shop, sum(number) number from table
GROUP BY country_shop
有输出