查询未返回任何内容,但必须至少返回1行

时间:2018-10-31 04:06:01

标签: postgresql

我在使用postgresql时遇到问题,如果在“是”或“否”状态中确认的结果行不返回任何内容,则仅显示空值,但我想在每个月中显示具有值的结果,如这个

enter image description here

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行且值时,我该如何做些技巧?

预先感谢

0 个答案:

没有答案