我在使用postgresql时遇到问题,如果在“是”或“否”状态中确认的结果行不返回任何内容,则仅显示空值,但我想在每个月中显示具有零值的结果,如这个
SELECT *
FROM crosstab
('SELECT
EXTRACT(YEAR FROM (TPH."TGLINSERT")) AS "TAHUN",
EXTRACT(MONTH FROM (TPH."TGLINSERT")) AS "BULAN",
SUM(TPH."GRANDTOTAL") AS "NOMINAL"
FROM
trans_h TPH
LEFT OUTER JOIN mcustomer MC ON MC."ID"=TPH."IDCUSTOMER"
WHERE
TPH."IDCUSTOMER"=373
AND TPH."CONFIRMED"=''Y''
AND EXTRACT(YEAR FROM (TPH."TGLINSERT"))=EXTRACT(YEAR FROM (NOW()))
GROUP BY 1,2','
SELECT m
FROM generate_series(1,12) m')AS ct
("TAHUN" int,"JAN" int,"FEB" int,
"MAR" int,"APR" int,"MAY" int,
"JUN" int,"JUL" int,"AUG" int,
"SEP" int,"OCT" int,"NOV" int,"DEC" int);
当查询什么都没有返回时,每个月至少必须显示1行且零值时,我该如何做些技巧?
预先感谢