在Metabase仪表板中按日期过滤不会

时间:2019-06-16 16:50:44

标签: sql postgresql business-intelligence metabase

不幸的是,我在本机date查询中通过sql进行过滤需要花费数小时的时间。有人具有丰富的元数据库经验吗?

select to_date("date", 'YYYYMMDD') AS Date, 
round(sum("price"), 2) AS "Revenue"
from "cdw_transactions"
group by Date
WHERE Date = {{Date}}

2 个答案:

答案 0 :(得分:0)

查询应重写为:

select to_date("date", 'YYYYMMDD') AS "Date", 
round(sum("price"), 2) AS "Revenue"
from "cdw_transactions"
where "date" = {{Date}}               -- where before grouping
group by to_date("date", 'YYYYMMDD'); -- matching select

答案 1 :(得分:0)

您应该在group by之前过滤 。但是,group by并没有实际需要,因为您只想返回一行。

我认为是这样的:

select {{Date}} AS Date, 
       round(sum("price"), 2) AS "Revenue"
from "cdw_transactions"
where to_date("date", 'YYYYMMDD') = {{Date}};