-1
I made a precedent in which I am trying to group the items with the same id_request, but the answer I get at the time of running is, each separate product, even though it still has the same id.
below is the code of my previous.
@id_cliente SMALLINT
AS
SELECT
c.id_cliente,
pe.id_pedido,
sp.descricao,
p.produto,
pe.data_inclusao,
e.id_pedido_endereco,
e.cep,
e.bairro,
e.cidade,
e.numero,
e.rua,
e.Uf,
SUM(pit.valor * pit.quantidade) AS total_pedido
FROM TR32_pedido pe
left join TR32_pedido_item pit on pit.id_pedido = pe.id_pedido
inner join TR32_status_pedido sp on sp.Id_status_pedido = pe.id_status_pedido
inner join TR32_cliente c on c.id_cliente = pe.id_cliente
left join TR32_pedido_endereco e on e.id_pedido = pe.id_pedido
left join TR32_produto p on p.id_produto = pit.id_produto
WHERE c.id_cliente=@id_cliente and pe.id_status_pedido!=1
group by c.id_cliente,
pe.id_pedido,
sp.descricao,
p.produto,
pe.data_inclusao,
e.id_pedido_endereco,
e.cep,
e.bairro,
e.cidade,
e.numero,
e.rua,
e.Uf
Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.
–
in my order table I have 11 items, but some have the same id_request, I’m trying to make a select process that brings together these items, in a way that all that contains the same id, come in a single line, since they have the same address, id, and I put the sum to calculate the sum of the price of each item with the amount the customer selected
– Person
put data to demonstrate the problem, can monstar an example here: http://sqlfiddle.com/
– Ricardo Pontual
if you are grouping and not grouping is pq another field used in query/group by is not being grouped. Start with a simple
SELECT pe.id_pedido FROM TR32_pedido pe GROUP BY pe.id_pedido
and then add the other fields until you find out who is duplicating the result– Ricardo Pontual