0
I am trying to group the data of my select , according to the field C9_CARGA , however when I run this select it returns me without being grouped , I believe I am doing something wrong .
SELECT Cast(Getdate() AS DATE),
Ltrim (Rtrim (c9_carga)) AS CARGA,
Ltrim (Rtrim (c6_filial)) AS FILIAL,
Ltrim (Rtrim (a4_nome)) AS TRANSPORTADORA,
Ltrim (Rtrim (dak_caminh)) AS PLACA,
Ltrim (Rtrim (da4_nome)) AS MOTORISTA,
Ltrim (Rtrim (da4_numcnh)) AS CNH,
Ltrim (Rtrim (da4_rg)) AS RG,
Ltrim (Rtrim (a1_nome)) AS NOME,
Ltrim (Rtrim (c6_num)) AS PEDIDO,
Ltrim (Rtrim (c6_produto)) AS PRODUTO,
Ltrim (Rtrim (c6_descri)) AS DESCRICAO,
Ltrim (Rtrim (c6_um)) AS UN,
Ltrim (Rtrim (c9_qtdlib)) AS QUANTIDADE,
b1_peso AS PESO_BRUTO
FROM sc9010
LEFT JOIN dak010
ON c9_filial = dak_filial
AND c9_carga = dak_cod
LEFT JOIN sc6010
ON c9_filial = c6_filial
AND c9_pedido = c6_num
AND c6_cli = c9_cliente
AND c6_loja = c9_loja
AND c6_item = c9_item
AND c6_produto = c9_produto
LEFT JOIN sb1010
ON b1_cod = c6_produto
LEFT JOIN sa1010
ON a1_cod = c6_cli
AND a1_loja = c6_loja
LEFT JOIN da3010
ON da3_filial = dak_filial
AND da3_cod = dak_caminh
LEFT JOIN da4010
ON da3_filial = da4_filial
AND da4_cod = da3_motori
LEFT JOIN sa4010
ON a4_cod = dak_transp
AND a4_filial = dak_filial
WHERE sc9010.d_e_l_e_t_ <> '*'
AND sc6010.d_e_l_e_t_ <> '*'
AND sc9010.d_e_l_e_t_ <> '*'
AND sb1010.d_e_l_e_t_ <> '*'
AND sa1010.d_e_l_e_t_ <> '*'
AND da3010.d_e_l_e_t_ <> '*'
AND da4010.d_e_l_e_t_ <> '*'
AND sa4010.d_e_l_e_t_ <> '*'
AND c9_carga <> ''
AND c9_nfiscal = ''
GROUP BY c9_carga,
c6_filial,
a4_nome,
dak_caminh,
da4_nome,
da4_numcnh,
da4_rg,
a1_nome,
c6_num,
c6_produto,
c6_descri,
c6_um,
c9_qtdlib,
b1_peso
does not necessarily mean that the field
C9_CARGA
is not being grouped, grouping includes all fields, any field in group by may be causing this, such as NAME, CNH or PESO_BRUTO for example. Select all fields without group by filtering for what appears repeated (where c9_carga=13974 and ....
) and see who’s causing the problem– Ricardo Pontual