我试图通过使用日期对组进行非常简单的查询,但是它给出了连续总和而不是分组总和
SELECT
sum(pit.preco) AS preco,
sum(pit.quantidade) AS quantidade
FROM cliente c
LEFT JOIN erp_pedido ped ON ped.id_cliente = c.id_cliente
LEFT JOIN erp_pedido_it pit ON pit.id_pedido = ped.id_pedido
WHERE ped.tipo = 'C'
AND ped.id_cliente = 2
GROUP BY
ped.data_inicio ,
c.nome,
ped.id_cliente
ORDER BY ped.data_inicio desc,
ped.id_cliente
是的,谢谢:
2017-03-01 00:00:00 ; CLIENT NAME ; 2 ; 1.5000 ; 209.0000
2017-02-01 00:00:00 ; CLIENT NAME ; 2 ; 3.0000 ; 418.0000
2017-01-01 00:00:00 ; CLIENT NAME ; 2 ; 4.5000 ; 627.0000
2016-12-01 00:00:00 ; CLIENT NAME ; 2 ; 6.0000 ; 836.0000
2016-11-01 00:00:00 ; CLIENT NAME ; 2 ; 7.5000 ; 1045.0000
2016-10-01 00:00:00 ; CLIENT NAME ; 2 ; 9.0000 ; 1254.0000
2016-09-01 00:00:00 ; CLIENT NAME ; 2 ; 10.5000 ; 1463.0000
2016-08-01 00:00:00 ; CLIENT NAME ; 2 ; 12.0000 ; 1672.0000
2016-07-01 00:00:00 ; CLIENT NAME ; 2 ; 13.5000 ; 1881.0000
2016-06-01 00:00:00 ; CLIENT NAME ; 2 ; 15.0000 ; 2090.0000
2016-05-01 00:00:00 ; CLIENT NAME ; 2 ; 16.5000 ; 2299.0000
我希望每一行都是相同的
PRECO ; QUANTIDADE
1.5000 ; 209.0000
1.5000 ; 209.0000
1.5000 ; 209.0000
1.5000 ; 209.0000
1.5000 ; 209.0000
1.5000 ; 209.0000
我不明白为什么它按顺序汇总每一行
*相加的行的内容可能不同,但在测试用例中它们只是相同的