postgresql 自定义SQL度量在Apache超集中不起作用

edqdpe6u  于 2023-04-11  发布在  PostgreSQL
关注(0)|答案(1)|浏览(67)

我试图在Apache Superset中使用自定义SQL创建自定义指标。我只写了简单的select,但它不起作用:

SELECT SUM(sales) AS "Sales" 
FROM SuperStore

我得到了一个错误“语法错误在或附近“SELECT”
我也试过这样的SQL:

SELECT "Sales"
FROM
(
SELECT SUM(sales) AS "Sales" 
FROM SuperStore)

但误差是相同的。
我想使用以下命令创建类别级别的销售额:

SELECT SUM(sales) OVER (PARTITION BY category) AS "CategorySales" 
FROM SuperStore

我该怎么办?
谢谢

ctzwtxfj

ctzwtxfj1#

在指标定义中,如果您决定创建自定义SQL指标,则应仅添加部分

SUM(sales) OVER (PARTITION BY category)

然后,您可以调用自定义指标CategorySales
超集将构建您的查询为

SELECT 
  SUM(sales) OVER (PARTITION BY category) as CategorySales
FROM SuperStore

现在的问题是,当您要将自定义指标添加为

SELECT SUM(sales) OVER (PARTITION BY category) AS "CategorySales" 
FROM SuperStore

超集将查询创建为

SELECT SELECT SUM(sales) OVER (PARTITION BY category) AS "CategorySales" 
FROM SuperStore AS "SELECT..." FROM SuperStore

相关问题