我在 BigQuery 中有一个创建日期和上次修改日期的任务。如果可能,我希望能够按日期在同一张表中报告任务打开和任务关闭事件的数量。
view: tasks {
derived_table: {
sql:
SELECT *
FROM UNNEST(ARRAY<STRUCT<CREATED_DATE DATE, LAST_MODIFIED DATE, ID INT64, STATE STRING>>[
('2020-12-01', '2020-12-01', 1, "OPEN"),
('2020-12-01', '2020-12-03', 2, "CLOSED"),
('2020-12-02', '2020-12-03', 3, "CLOSED"),
('2020-12-03', '2020-12-05', 4, "OPEN"),
('2020-12-05', '2020-12-05', 5, "CLOSED")])
;;
}
dimension_group: created {
type: time
datatype: date
sql: ${TABLE}.created_date ;;
}
dimension_group: last_modified {
type: time
datatype: date
sql: ${TABLE}.last_modified ;;
}
dimension: id {
type: number
}
dimension: state {
type: string
}
measure: number_of_tasks {
type: count_distinct
sql: ${id} ;;
}
measure: number_of_open_tasks {
type: count_distinct
sql: ${id} ;;
filters: {
field: "state"
value: "OPEN"
}
}
measure: number_of_closed_tasks {
type: count_distinct
sql: ${id} ;;
filters: {
field: "state"
value: "CLOSED"
}
}
}
explore: tasks {}
我可以使用创建日期获取打开任务的数量。
我可以通过计算任务来获得关闭的任务数量,其中最后修改日期在聚合期间并且状态为关闭,并带有过滤度量。
但是,如果我尝试将这些组合在一个表中,我会为每个日期组合得到一行。
如何按日期计算任务状态更改?
日期 | 打开的任务数 | 已关闭任务数 |
---|---|---|
2020-12-01 | 2 | 0 |
2020-12-02 | 1 | 0 |
2020-12-03 | 1 | 2 |
2020-12-04 | 0 | 0 |
2020-12-05 | 1 | 1 |