Hi i have installed prestashop, i want report from mysql, Number of orders per customer with customer name & customer id plus i want total amount of order customer wise.

can you help me with SQL query so i can generate this report from phpmyadmin.



Recommended Answers

All 4 Replies

What are the table structures, and what have you tried?

i have tried below code, but getting syntax error.

SELECT customers_firstname, customers_lastname,o.Number
FROM customers 
INNER JOIN (Select customer_id, count(*) as Number from orders Group by customer_id order by Number desc limit 5)AS o
on customers.customers_id = o.customer_id ;

#1064 - you have an error in your sql syntax (line number 5)

I am writing sample query

select a.id_customer, b.firstname,b.lastname, count(*) total_orders from orders a inner join customer b on a.id_customer=b.id_customer group by a.id_customer b.firstname,b.lastname

thanks, i have littlebit modified & its working. thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.