Query the customer_number from the orders table for the customer who has placed the largest number of orders.

It is guaranteed that exactly one customer will have placed more orders than any other customer.

The orders table is defined as follows:

| Column            | Type      |
|-------------------|-----------|
| order_number (PK) | int |
| customer_number | int |
| order_date | date |
| required_date | date |
| shipped_date | date |
| status | char(15) |
| comment | char(200) |

Sample Input

| order_number | customer_number | order_date | required_date | shipped_date | status | comment |
|--------------|-----------------|------------|---------------|--------------|--------|---------|
| 1 | 1 | 2017-04-09 | 2017-04-13 | 2017-04-12 | Closed | |
| 2 | 2 | 2017-04-15 | 2017-04-20 | 2017-04-18 | Closed | |
| 3 | 3 | 2017-04-16 | 2017-04-25 | 2017-04-20 | Closed | |
| 4 | 3 | 2017-04-18 | 2017-04-28 | 2017-04-25 | Closed | |

Sample Output

| customer_number |
|-----------------|
| 3 |

Explanation

The customer with number '3' has two orders, which is greater than either customer '1' or '2' because each of them  only has one order. 
So the result is customer_number '3'.

Follow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?

Code

SELECT customer_number FROM orders GROUP BY customer_number HAVING count(*) >= ALL (SELECT count(*) FROM orders GROUP BY customer_number)

最新文章

  1. 关于编程一些鲜为人知的真相 csdn
  2. iOS button文字居中
  3. Drainage Ditches(Dinic最大流)
  4. 说说PHP的autoLoad自动加载机制
  5. jquery背景动画插件使用
  6. android 物理按键 监听
  7. [Unity]Unity开发NGUI代码实现ScrollView(放大视图)
  8. Navicat连接阿里云服务器Linux下的Mysql
  9. ImageUtil
  10. 洛谷题解 CF807A 【Is it rated?】
  11. 2 c++对象被使用前要先被初始化
  12. 2018-10-23 23:29:54 clanguage
  13. [py]处理文件的3个方法
  14. Mysql5.7 的错误日志中最常见的note级别日志解释
  15. del
  16. linux 虚拟网络模型介绍
  17. 关于数学问题的urls
  18. HDU1010 Tempter of the Bone(回溯 + 剪枝)
  19. MapReduce中的排序(附代码)
  20. JAVA中重写equals()方法为什么要重写hashcode()方法说明

热门文章

  1. Jenkins解决无法获取插件的办法(升级站点目录)
  2. ABP之展现层(导航菜单)
  3. xml配置
  4. SQL多结果集导出Excel
  5. mapReducer 去重副的单词
  6. SQLServer 索引重建
  7. expect远程登录服务器并执行命令
  8. MathType怎么打定积分竖线
  9. 结构体指针 Pointers to Structures struct Books Book1; struct Books *struct_pointer;
  10. mail 发送email