用 postgresql (javascript) 中的月份和日期 table 填写 HTML table
fill in a HTML table with all days of month and date table from postgresql (javascript)
我不明白如何使用 generate_series 填充 HTML table 其中 <tr>
的 'key' 是一个月中的几天取决于用 <input type='month'>
.
编辑 select 的月份和年份
目前(多亏了我在这里得到的答案),我生成的查询仅在 select 月份和 select 月份为我提供月份和年份的日期。
像这样:
SELECT
*
FROM (
SELECT
folio,
fecha,
extract(month FROM fecha) = AS mes,
EXTRACT(YEAR FROM fecha) = AS anio,
temperatura
FROM
medicion) m
WHERE
mes = TRUE
AND anio = TRUE
ORDER BY
fecha ASC
并在 HTML table:
中得到了这个
fecha
temperatura
2022-03-04
60
2022-03-07
50
2022-03-09
70
但我需要这样的东西:
fecha
temperatura
2022-03-01
0
2022-03-02
0
2022-03-03
0
2022-03-04
60
2022-03-05
0
2022-03-06
0
2022-03-07
50
2022-03-08
0
2022-03-09
70
2022-03-10
0
所有的日子,每个月都不同。
像这样:
SELECT
t.dt,
coalesce(temperatura, 0)
FROM
generate_series('03/01/2022'::timestamp, (('03/01/2022'::timestamp + interval '1 month') - interval '1 day'), '1 day') AS t (dt)
LEFT JOIN
medicion ON t.dt = medicion.fecha;
这假设 medicion.fecha
是一个 date
字段。此外,您还需要根据 input
值构建 generate_series()
的开始日期才能输入函数,例如 $3/01/$4
我不明白如何使用 generate_series 填充 HTML table 其中 <tr>
的 'key' 是一个月中的几天取决于用 <input type='month'>
.
目前(多亏了我在这里得到的答案),我生成的查询仅在 select 月份和 select 月份为我提供月份和年份的日期。
像这样:
SELECT
*
FROM (
SELECT
folio,
fecha,
extract(month FROM fecha) = AS mes,
EXTRACT(YEAR FROM fecha) = AS anio,
temperatura
FROM
medicion) m
WHERE
mes = TRUE
AND anio = TRUE
ORDER BY
fecha ASC
并在 HTML table:
中得到了这个fecha | temperatura |
---|---|
2022-03-04 | 60 |
2022-03-07 | 50 |
2022-03-09 | 70 |
但我需要这样的东西:
fecha | temperatura |
---|---|
2022-03-01 | 0 |
2022-03-02 | 0 |
2022-03-03 | 0 |
2022-03-04 | 60 |
2022-03-05 | 0 |
2022-03-06 | 0 |
2022-03-07 | 50 |
2022-03-08 | 0 |
2022-03-09 | 70 |
2022-03-10 | 0 |
所有的日子,每个月都不同。
像这样:
SELECT
t.dt,
coalesce(temperatura, 0)
FROM
generate_series('03/01/2022'::timestamp, (('03/01/2022'::timestamp + interval '1 month') - interval '1 day'), '1 day') AS t (dt)
LEFT JOIN
medicion ON t.dt = medicion.fecha;
这假设 medicion.fecha
是一个 date
字段。此外,您还需要根据 input
值构建 generate_series()
的开始日期才能输入函数,例如 $3/01/$4