S
S
Stardust2020-05-28 20:30:06
MySQL
Stardust, 2020-05-28 20:30:06

How to generate a report on customer orders?

People, help me understand...
I have this transaction
Input data - Date 1, Date 2
Select order ID, Order date, Product, Quantity of goods, Cost, Status, Manager from tables Customer, Order, Product
By condition Order date> = Date 1 and Order Date <= Date 2 and Client_ID = Authorized User ID

I write the following query for this transaction:
SELECT zakaz.id_zakaz, name_product, datazak, price, status, fio_manager, SUM(product.price*zakaz.kolich) as 'Sum of orders', SUM(zakaz.kolich)
as 'Total quantity of goods' FROM client,zakaz,tovar,manager
where client.id_client=zakaz.id_client
and manager.id_manager=zakaz.id_manager
and tovar.id_tovar=zakaz.id_tovar
and client.id_client=2 and datazak BETWEEN '2020-05-05' AND '2021-05-12';
I get the following answer... How to write a query so that all customer orders are displayed, and the amount and quantity of goods are considered total? Thanks...5ecff5121377e573833074.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Tsisar, 2020-05-29
@MaksTR

Is the sum of orders and the total quantity of goods the total data for the customer? If this is the case, then try moving the calculation into a separate query
SELECT ... Sums.TotalSum, Sums.TotalNumber ...
FROM client,zakaz,tovar,manager, (SELECT zakaz.id_client AS ClientId, SUM(product.price*zakaz. kolich) AS TotalSum, SUM(zakaz.kolich) AS TotalNumber FROM zakaz,tovar WHERE tovar.id_tovar=zakaz.id_tovar GROUP BY zakaz.id_client) Sums
WHERE ... AND client.id_client = Sums.ClientId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question