我试图显示第一个表“articulos_temp”中的整行,但它不起作用。假设我想计算 Facturas 表中的寄存器数量,但如果 Facturas 表中没有行,那么它将显示 articulos_temp 表中的列 但是当我运行查询时,我只得到 1172 行,这是错误的,因为我在表 articulos_temp 中得到 2485 行,它应该必须显示第一个表中的 2485 行
有什么想法吗?
SELECT AT.Material, coalesce (count(FD.Cantidad),AT.Cantidad) AS Cantidad
FROM articulos_temp AS AT WITH (NOLOCK)
LEFT JOIN Facturasdetalle AS FD WITH (NOLOCK)
ON AT.Material = FD.Codigo
JOIN Facturas AS F WITH (NOLOCK) ON F.IdVenta = FD. idFactura
WHERE F.Cancelado\<\>1
AND CAST(F.fecha As DATE) BETWEEN '20220301' AND '20220331'
GROUP BY AT.Material, --AT.Descripcion_Material,
AT.Cantidad, fd.Cantidad
ORDER BY AT.Material