错误:“SETS”或其附近的语法错误

时间:2018-01-09 18:29:23

标签: postgresql

尝试在Postgres DB中使用GROUPING SETS函数时出现语法错误。

我查看了文档here,我相信语法是正确的,但我仍然遇到错误。

我认为语法应为GROUP BY GROUPING SETS ((COLUMN), (COLUMN), ()),以便从我的代码的SUM()部分获得SELECT的总计。所以我放入了GROUP BY GROUPING SETS ((amount.date), ( places.place), ());

我在这里做错了什么?

SELECT 

  EXTRACT(MONTH FROM amount.date),
  places.place,
  CASE
      WHEN places.place = 'A' THEN SUM(amount.amount)
      WHEN places.place = 'B' THEN SUM(amount.amount)
      WHEN places.place = 'C' THEN SUM(amount.amount)
      ELSE SUM((amount.amount) * 2.5)
  END  AS "Total"

FROM amount

LEFT JOIN places                            ON places.id = amount.id

WHERE EXTRACT(YEAR FROM amount.date) = 2017

GROUP BY GROUPING SETS ((amount.date), (places.place), ());

0 个答案:

没有答案