1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

List by ascending number of orders the customers that have placed more than 1 order?

Discussion in 'SQL - Questions and Answers' started by alexfr, May 24, 2006.

  1. alexfr New Member

    Dialect: SQL 92
    List by ascending number of orders the customers that have placed more than 1 order
  2. alexfr New Member

    Dialect: SQL 92
    SQL:
    SELECT c.id, c.firstname, c.lastname, COUNT(o.order_id) as total
    FROM customers c INNER JOIN orders o ON c.customer_id = c.customer_id
    GROUP BY c.customer_id, c.lastname
    HAVING COUNT(o.order_id) > 1
    ORDER BY COUNT(o.order_id) ASC

Share This Page