[英]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.