How to get order output after using a group in a SQL query?

I have a sql table with the names and orders of customers that they place over time.

table column names: id, customer name, order value, status, as well as created and changed.

I can group customer names and the number of orders.

using sql query like this.

SELECT Customer,count(OrderPrice) FROM Orders GROUP BY Customer

It works great. But I want the result to be ordered by the number of orders (quantity). A customer with a large number of orders is at the top of the list.

I appreciate any help.

Thank.

+3
source share
2 answers
    SELECT Customer
         , count(OrderPrice) cnt
      FROM Orders
  GROUP BY Customer
  ORDER BY cnt DESC
+5
source

,          count (OrderPrice) order_count      GROUP BY Customer   ORDER BY order_count desc

!

+1

Source: https://habr.com/ru/post/1757897/


All Articles