586. Customer Placing the Largest Number of Orders

原创 2018年04月17日 07:07:13

思路:原题只有exactly one 最大订单数量,group by之后用订单量降序排列,并limit取第一个值

如果不止一个最大订单数,找出最大订单值,然后找出订单量等于这个值的就可以了。

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'.
select customer_number
from orders
group by customer_number
order by count(*) desc
limit 1;

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

select customer_number
from orders
group by customer_number
having count(*) = 
(select max(cnt) from 
(select count(*) cnt
from orders
group by customer_number))


【LeetCode】Largest Number 解题报告

【题目】 Given a list of non negative integers, arrange them such that they form the largest number...
  • ljiabin
  • ljiabin
  • 2015-01-13 15:04:39
  • 11403

179 Largest Number

题目链接:https://leetcode.com/problems/largest-number/题目:Given a list of non negative integers, arrange ...
  • ChilseaSai
  • ChilseaSai
  • 2016-01-31 22:03:04
  • 793

LeetCode(179) Largest Number

题目如下: Given a list of non negative integers, arrange them such that they form the largest number. F...
  • feliciafay
  • feliciafay
  • 2015-01-21 15:58:05
  • 2664

LeetCode--Largest Number(最大数字)Python

题目: 给定一个包含非负数的列表,重新排列,使其最终组合之后的整数最大。例如:给定列表[3, 30, 34, 5, 9], 返回的最大整数是9534330 解题思路: 相当于对列表中的数字进行排...
  • xiaoxiaoley
  • xiaoxiaoley
  • 2017-11-29 15:13:09
  • 82

Codeforces946E Largest Beautiful Number

传送门:Codeforces946E 题意:给定一个数字,求一个比该数字小,且是漂亮数字的数字漂亮数字:不一定求得的数字就是回文数字,要求数位上的所有数字排列组合后是个回文数字分析: 贪心数据比较小,...
  • computer_user
  • computer_user
  • 2018-03-07 19:28:47
  • 235

LeetCode Largest Number 贪心

将数组中的元素进行重排,组成最大的数。 如果只有两个数,可以简单判断:,使用贪心,将数组中的元素按照上述比较规则进行降序排序,进行拼接即为所求。证明如下: 假设按照贪心得到的最优解为:(其中),若存在...
  • ww32zz
  • ww32zz
  • 2016-02-10 22:03:41
  • 288

leetcode-747. Largest Number Greater Than Twice of Others

747. Largest Number Greater Than Twice of Others In a given integer array nums, there is always ex...
  • qq_32832023
  • qq_32832023
  • 2017-12-25 12:26:17
  • 467

[Leetcode] 179. Largest Number @python

题目Given a list of non negative integers, arrange them such that they form the largest number.For exa...
  • qian2729
  • qian2729
  • 2016-02-05 17:00:05
  • 513

Educational Codeforces Round 39-E-Largest Beautiful Number(暴力)

题意:给你一个很大的数,问你小于该数的最大的优美数是多少(优美数:每一位上出现的数字都出现偶数次) 题解:直接从最后一位开始让该位减一(直到该位减到0),判断前边与后边加上该位是否符合题意,若不符合...
  • haut_ykc
  • haut_ykc
  • 2018-03-08 10:51:22
  • 55

747. Largest Number At Least Twice of Others。

In a given integer array nums, there is always exactly one largest element.Find whether the largest ...
  • Leafage_M
  • Leafage_M
  • 2018-01-07 21:12:12
  • 494
收藏助手
不良信息举报
您举报文章:586. Customer Placing the Largest Number of Orders
举报原因:
原因补充:

(最多只允许输入30个字)