总共2个table
Sample table1:  <--名字是customer
customerID   customerName
        1            sima
        2            melven
        3            spidey
        4            anna
        5            squallsohSample table2:  <--名字是orders
orderID     customerID     orderItem
     1              2            pen
     2              2            rubber
     3              1            pen
     4              2            books
     5              5            books
Task: write an SQL query to identify which customer has the most orders in the systems
(找出那个customer下了最多的order)

解决方案 »

  1.   

    select o.customerID,c.customerID,count(*)
    from orders o inner join customer c on o.customerID=c.customerID
    group by o.customerID,c.customerID
    order by 2 desc
    limit 1
    [align=center]====  ====
    [/align]
      

  2.   

    2 desc 跟 limit 1是 指什么的呢 》??
      

  3.   

    order by 2 desc 按第二列的值以降序排序,也就是count(*)
    limit 1 限制输出记录数,仅1条记录,也就是最大的那条[align=center]====  ====
    [/align]