简体   繁体   English

如何转义用作列名的保留字? 谷歌数据工作室

[英]How do I escape reserved words used as column names? Google Data Studio

I am using Google data studio to produce some data dashboards, as part of this I am creating a calculated field on the dataset that strips the numeric value from an alphanumeric string ie 7 out of 7A.我正在使用 Google 数据工作室生成一些数据仪表板,作为其中的一部分,我在数据集上创建了一个计算字段,该字段从字母数字字符串中剥离数值,即 7 out of 7A。

I'm then using a case statement to assign another number to the striped value ie where the formula returns 7 the case statement assigns this to 1000, 8 as 2000, 9 to 3000 ect然后我使用 case 语句将另一个数字分配给条纹值,即公式返回 7 的情况下,case 语句将其分配给 1000、8 作为 2000、9 到 3000 等

The problem I am having is that in the dataset three of the fields are titled 7, 8 and 9. As such in the below formula the first three lines are comparing the striped field to the fields titled 7, 8 or 9 and not to the numeric value of 7, 8 or 9我遇到的问题是,在数据集中,三个字段的标题为 7、8 和 9。因此,在下面的公式中,前三行将条纹字段与标题为 7、8 或 9 的字段进行比较,而不是与数值 7、8 或 9

I need to be able to escape the 7,8 or 9 characters in the formula so they are treated as a numeric value and not a referance to a field in the dataset.我需要能够转义公式中的 7,8 或 9 个字符,以便将它们视为数值而不是对数据集中字段的引用。

case
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 7 then 1000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 8 then 2000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 9 then 3000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 10 then 4000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 11 then 5000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 12 then 6000
    when CAST(REGEXP_REPLACE(YearGroup, R"\D+", "") AS NUMBER)= 13 then 7000
end

To strip a part of a string, please use REGEXP_EXTRACT .要去除字符串的一部分,请使用REGEXP_EXTRACT

First check for a number, the text may only contain digits.首先检查一个数字,文本可能只包含数字。 If it is a number convert the text field to a number.如果是数字,则将文本字段转换为数字。

If the text field contains digits ( \d+ ) followed by a none digit ( \D ), the extract the digits.如果文本字段包含数字 ( \d+ ) 后跟一个无数字 ( \D ),则提取数字。 Convert it to a number and do your calculation.将其转换为数字并进行计算。

CASE
  WHEN REGEXP_MATCH(YearGroup, r"\d+") THEN CAST(YearGroup AS number )
  WHEN CAST(REGEXP_EXTRACT(YearGroup, r"(\d+)\D") AS number ) BETWEEN 7 AND 13 THEN 
    1000 * ( CAST(REGEXP_EXTRACT(YearGroup, r"(\d+)\w") AS number ) - 6 )
  ELSE NULL
END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 google data studio 添加安全组以访问我的 amayon RDS? - How do I add security group for google data studio to access my amayon RDS? 如何购买 AWS t2.medium 预留实例? - How do I Purchase AWS t2.medium Reserved instance? Google Container Registry:防止一组用户推送保留标签名称 - Google Container Registry : Prevent a group of users to push reserved tag names Firebase | 谷歌表 | 应用脚本 | 如何将列中的数据而不是行中的数据从 Firebase 保存到 Google 表格? - Firebase | Google Sheet | App Script | How do I save the data in column instead of row from Firebase to Google Sheet? 如何保护用作 Diaglogflow / Google Action 主机的 Google 云 function - How do I secure a Google cloud function being used as the host for a Diaglogflow / Google Action 如何在 Data Studio 中删除所有这些 null 值? - How do I get rid of all these null values in Data Studio? 如何将两个类别的值相加并显示在 Google Data Studio 的柱形图中? - How to sum up values of two category and show in a column chart in Google Data Studio? 如何在 Azure Synapse 中找到 HASH DISTRIBUTION 中使用的列? - How do I find the column used in a HASH DISTRIBUTION within Azure Synapse? 如何更改 Redshift 中的列数据类型? - How do I change column data type in Redshift? 如何在 Google Data Studio 中显示单个日期? - How to Display a single Date in Google Data Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM