在元数据库中设置一个仅包含月份值的下拉菜单(一月至十二月)PostgreSQL

时间:2019-11-26 10:06:25

标签: postgresql metabase

我目前正试图仅在几个月内制作一个下拉菜单

下面是我的代码:

SELECT
avg(Monthly_Calls), district, “Crops”, “Months”, “Date”

FROM(
SELECT date_part(‘month’, t.created_on::date) as “Months”,
COUNT(*) AS Monthly_Calls,
t.created_on::date as “Date”,
district_name as district,
date_part(‘year’, t.created_on::date) as “Years”,
t.crop as “Crops”
FROM t
where true
[[and {{Crops}}]]
[[and date_part(‘month’, t.created_on::date) = {{Months}}]]
GROUP BY district_name, date_part(‘month’, t.created_on::date), date_part(‘year’, t.created_on::date), crop, created_on
)calls

where “Years” between 2012 and 2018
GROUP BY district, “Months”, “Crops”, “Date”, “Years”

我只设法获取了月份值,我可以将其返回并显示在区域地图中,但我想使月份成为下拉列表,就像“作物”菜单中包含来自1-12(数据库中没有月份,数据库仅具有created_on,这是一个日期,即2018-09-12)我在配置数据库中使用PostgreSQL数据库

任何帮助都很好,谢谢!

以下是该月所需输出的屏幕截图 Crop dropdown image

0 个答案:

没有答案