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)

[LeetCode] 586. Customer Placing the Largest Number of Orders_Easy tag;SQL的更多相关文章

  1. [LeetCode] Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  2. JavaScript中sort方法的一个坑(leetcode 179. Largest Number)

    在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...

  3. Leetcode:Largest Number详细题解

    题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...

  4. [LeetCode][Python]Largest Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/largest ...

  5. LeetCode之“排序”:Largest Number

    题目链接 题目要求: Given a list of non negative integers, arrange them such that they form the largest numbe ...

  6. 【Leetcode】179. Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  7. leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数

    这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...

  8. [LeetCode] 179. Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. Example ...

  9. LeetCode 179. 最大数(Largest Number) 21

    179. 最大数 179. Largest Number 题目描述 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 每日一算法2019/5/24Day 21LeetCode179. La ...

随机推荐

  1. rx.js 的冷和热观察

    http://cn.rx.js.org/manual/overview.html#h213 https://rxjs-cn.github.io/rxjs5-ultimate-cn/content/ho ...

  2. 微信小程序获取到Openid

    前台代码片段 onLoad: function () { wx.login({ success(res) { console.log('code: '+res.code) if (res.code) ...

  3. Mapper 赋值对应实体属性

    public static class MapperExtensions { public static TResult MapTo<TResult>(this object self, ...

  4. python 同时运行两个程序

    linux的话: python py1.py & python py2/py &

  5. PHP之null

    null类型 特殊的null值表示一个变量没有值.null类型唯一可能的值是null. 在下列情况下一个变量被认为是null: ①.被赋值为null ②.尚未被赋值 ③被unset(). 语法 nul ...

  6. 最全最详细:ubuntu16.04下linux内核编译以及设备驱动程序的编写(针对新手而写)

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  7. Newtonsoft.Json 转换DateTime类型为字符串时,串内部会有一个T。解决方案

    使用Newtonsoft.Json 转换DateTime类型时,若使用标准转换,则字符串内会有一个T(虽然再转换成DateTime没有问题). 若要转换成DateTime没有T,可以加上特性: pub ...

  8. LeetCode 812 Largest Triangle Area 解题报告

    题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be for ...

  9. idea+maven+springboot+mybatis+springmvc+shiro

    springboot就是把创建项目简单化,省去了以往的配置mybatis.springmvc的繁琐过程. 搭建web应用三个主要功能,请求和响应,数据库交互,权限配置. 一.idea创建项目 (1) ...

  10. Swift中"#"的用法

    配置外部参数名 在函数(或者方法)的参数名前添加"#",可以使该参数拥有相同的本地参数名和外部参数名. 注:在方法中,第二个及后续的参数,默认是具有和内部参数一致的外部参数名的,只 ...