sql - Google Data Studio 上的案例
问题描述
我试图在数据工作室上创建一个使用“case when”和函数 Date_diff 的字段。我不断收到错误“无法解析公式”。
- 我是否需要指定两个日期之间差异的指标(就像我在 BigQuery 上所做的那样)?
- 我可以用数字而不是字符串来命名值吗(尽可能在 BigQuery 上做)?
- 我需要将所有字段转换为日期格式,还是 Data Studio 自己将它们识别为日期?
- 我可以使用“Between”功能吗?
我的最新版本(不起作用)如下:
case when date_diff(cast(checkin as date),order_date,day)>=0 and <=3 then 3
when date_diff(cast(checkin as date),order_date,day)>=4 and <=7 then 7
when date_diff(cast(checkin as date),order_date,day)>=8 and <=14 then 14
when date_diff(cast(checkin as date),order_date,day)>=15 and <=30 then 30
when date_diff(cast(checkin as date),order_date,day)>=31 and <=60 then 60
when date_diff(cast(checkin as date),order_date,day)>=61 and <=180 then 180
when date_diff(cast(checkin as date),order_date,day)>=181 and <=365 then 365
end
解决方案
这是你的条件:
(case when date_diff(cast(checkin as date), order_date, day) >= 0 and <= 3 then 3
. . .
这没有意义。您可以将其表示为
(case when date_diff(cast(checkin as date), order_date, day) between 0 and 3 then 3
我更倾向于把它写成:
(case when checkin >= order_date and checkin < date_add(order_date, interval 4 day)
根据底层列的类型,您可能需要各种强制转换才能完成这项工作。
推荐阅读
- java - 如何将对象集合转换为arraylist
- python - 使用 Python RegEx 分离 SSL 证书
- android - 如何在我的 Android 项目中添加带有 API-Data 的饼图
- css - 在 CSS 中使用“target”时显示所有内部块
- python - 先创建 Django 应用还是虚拟环境?
- perl - Parse::RecDescent 和语法
- xml - 我正在尝试“嵌套” xsl:for-each (我认为)
- css-float - 为什么在 css 上应用浮点数时 div 元素被压扁?
- angular - Karma 或 TypeScript 编译器告诉我“字符串”类型上不存在属性“padStart”
- awk - 为什么有几个 Linux 发行版默认提供 mawk,即使它不符合 POSIX 标准?