ChartJS 当某些信息不存在时返回0(存在时不返回,返回空值)

nxagd54h  于 2022-11-07  发布在  Chart.js
关注(0)|答案(1)|浏览(165)

每个人。我有一个 query,它返回一个包含我需要的值的表。这很好。但我还需要,对于每个已经返回的日期,它也返回qtde_produzida的值0(这意味着“生产的数量”),在没有为该op_filha生产任何东西的日子里。例如:在下面的例子中,过滤器返回两个子产品(每个子产品有一个op_filha),并且还返回每个子产品的生产数量(显然,对于有生产的日子),但是我希望看到没有生产的日子的值为0。这可能吗?
我的 * 查询 *:

DECLARE @dtInicial1 AS varchar(11), @dtFinal1 AS varchar(11), @opId1 AS INT, @setorId1 AS INT

SET @dtInicial1 = '2022-04-20'
SET @dtFinal1 = '2022-05-24'
SET @opId1 = 101855
SET @setorId1 = 6

SELECT
    DISTINCT MAX(CONVERT(varchar, C.con_dt_fim, 103)) AS data_final --final_date
    ,SUM(C.con_qtde_fim) AS qtde_produzida --qtty-produced
    ,R.rast AS op_filha --id for subproduct
    ,SP.Descricao AS descricao --subproduct's name
FROM
    Rastreio AS R
    INNER JOIN Contagem AS C ON C.rastreio_id = R.rast_id AND C.con_dt_exc IS NULL AND C.con_qtde_fim > 0
    INNER JOIN [DBG].[dbo].SubProduto AS SP ON OP.Cod_Produto = SP.CodigoSubProduto
WHERE
    R.op_id = @opId1
    AND OP.Cod_Setor = @setorId1
    AND FORMAT(C.con_dt_fim, 'MM-dd') BETWEEN FORMAT(CAST(@dtInicial1 AS DATE), 'MM-dd') AND FORMAT(CAST(@dtFinal1 AS DATE), 'MM-dd')
GROUP BY
    R.rast
    ,SP.Descricao
    ,R.rast_processo_sequencia
ORDER BY
    data_final

打印退回内容的屏幕:enter image description here
这是针对一个 * Chart.js *'图表的。我想象一个 query 会返回如下内容:enter image description here
有没有人知道怎么做,拜托?谢谢大家的阅读。

gmxoilav

gmxoilav1#

您只需要一个ISNULL。请尝试以下操作:

SUM(ISNULL(C.con_qtde_fim,0)) AS qtde_produzida

ISNULL(SUM(C.con_qtde_fim),0) AS qtde_produzida

相关问题