如何在bigQuery中查询特定产品的每日费用?

时间:2019-04-30 09:03:23

标签: google-bigquery

我将帐单导出到bigquery,我想从bigQuery每月或特定日期获取特定日期的翻译总费用。例如2019年4月1日。

google docs示例查询每月获取一次。

SELECT
  invoice.month,
  SUM(cost)
    + SUM(IFNULL((SELECT SUM(c.amount)
                  FROM UNNEST(credits) c), 0))
    AS total,
  (SUM(CAST(cost * 1000000 AS int64))
    + SUM(IFNULL((SELECT SUM(CAST(c.amount * 1000000 as int64))
                  FROM UNNEST(credits) c), 0))) / 1000000
    AS total_exact
FROM `project.dataset.gcp_billing_export_v1_XXXXXX_XXXXXX_XXXXXX`
GROUP BY 1
ORDER BY 1 ASC
;

但是我是通过以下方式创建查询的:

$myVariable=
    "SELECT 
          COUNT(*) total_times,
          SUM(cost) total_cost
    FROM 
          `project.dataset.gcp_billing_export_v1_XXXXXX_XXXXXX_XXXXXX`
    WHERE 
          service.description = 'Translate' AND (usage_end_time >= timestamp('2019-04-04 00:00:00') AND usage_end_time <= timestamp('2019-04-04 23:59:59'))";

我想要获取当天的总费用以及从当月第一天到当天的总费用。

sample:
1. 2019/04/04: 4223.05 - (882 Times)
2. 2019/04/Total: 16505.43 - (3882 Times)

1 个答案:

答案 0 :(得分:2)

您可以进一步在工作查询中添加详细信息:

<prosody rate="slow" pitch="-2st">Can you hear me now?</prosody>
<prosody rate="medium" pitch="1st">Can you hear me now?</prosody>
<prosody rate="high" pitch="5st">Can you hear me now?</prosody>

其中显示:

enter image description here

如果您编辑第3行,则可以进一步细分为HOURly。