-2
Wanted a help on how to solve the last 3 selects down.
Recalling that the reports that contain the item "Total quantity" demand the total quantity of the product taking into account all the orders made.
SELECT pedido.horario_pedido AS horario,
pedido.nome_cliente AS nome,
nome_pedido.lista_pedido AS pedido,
query_total_preco.valor_total,
contato???
FROM
pedido
JOIN
itens_pedido itens
ON
pedido.id_pedido
=
itens.pedido_id_pedido
JOIN
(
SELECT
pedido.id_pedido AS id_pedido,
string_agg(produto.nome,', ') AS lista_pedido
FROM
itens_pedido pedido
JOIN
produto
ON
pedido.produto_id_produto = produto.id_produto
GROUP BY
pedido.id_pedido
) AS nome_pedido
ON
pedido.id_pedido = nome_pedido.id_pedido
JOIN
(SELECT pedido_id_pedido AS id_pedido,
SUM(valor_total) AS valor_total
FROM
itens_pedido
GROUP BY (pedido_id_pedido) ) AS query_total_preco
ON
nome_pedido.id_pedido = query_total_preco.id_pedido
I even started trying to do the second but don’t leave
If you could help me I’d be grateful
Possible duplicate of Summation in SQL
– arllondias
@It doesn’t seem duplicate.
– Victor Stafusa
puts in sqlFiddle... does not have the structure of tables...
– Rovann Linhalis
just a minute I put
– Gabriel Falieri
the structure of the bank and the fiddle
– Gabriel Falieri
Rsrs, the fiddle, has to be in the Sqlfiddle... but...
– Rovann Linhalis
how does it work?
– Gabriel Falieri
on the one hand, puts the code of creation of tables and Inserts, build in the schema, and on the other hand, realizes the queries
– Rovann Linhalis
Dude, can you open a chat between us?
– Gabriel Falieri
@Gabrielfalieri You must have at least 15 points to participate in chats on this site.
– Victor Stafusa