programming-examples/sql/FormattingOutput/Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first.sql

7 lines
342 B
MySQL
Raw Normal View History

2019-11-18 14:05:53 +01:00
/*Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the
customer will come first along with their highest purchase amount.*/
SELECT customer_id, COUNT(DISTINCT ord_no),
MAX(purch_amt)
FROM orders
GROUP BY customer_id
ORDER BY 2 DESC;