[LeetCode] 586. Customer Placing the Largest Number of Orders_Easy tag;SQL
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的更多相关文章
- [LeetCode] Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- JavaScript中sort方法的一个坑(leetcode 179. Largest Number)
在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...
- Leetcode:Largest Number详细题解
题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...
- [LeetCode][Python]Largest Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/largest ...
- LeetCode之“排序”:Largest Number
题目链接 题目要求: Given a list of non negative integers, arrange them such that they form the largest numbe ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数
这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...
- [LeetCode] 179. Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. Example ...
- LeetCode 179. 最大数(Largest Number) 21
179. 最大数 179. Largest Number 题目描述 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 每日一算法2019/5/24Day 21LeetCode179. La ...
随机推荐
- 网络通信协议二之ISO/OSI参考模型
OSI介绍 >>Open System Interconnection,简称ISO/OSI RM >>是一个逻辑结构,并非一个具体的计算机设备或网络 >>任何两个遵 ...
- PHP 设置分页 可以直接引用 最下面有自己引用的方法和注释
1 <?php 2 /** 3 file: page.class.php 4 完美分页类 Page 5 */ 6 class Page { 7 private $total; //数据表中总记录 ...
- Linux----知识储备
----------------------------------------------------------------------基础---------------------------- ...
- asp.net 访问页面访问统计实现 for iis7
上一篇博文中< asp.net 访问页面访问统计实现 > 中在win10 (iis8+)上运行没有问题, 但客户机子是windows server 2008 的 iis7弄死不对,最好 ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- [No0000174]Spring常用注解(收藏大全)
Spring部分 1.声明bean的注解 @Component 组件,没有明确的角色 @Service 在业务逻辑层使用(service层) @Repository 在数据访问层使用(dao层) @C ...
- 用CSS画基本图形
用CSS画基本图形 1.正方形 代码如下: #square { width: 100px; height: 100px; background: red; } 2.长方形 代码如下: #recta ...
- dyld环境变量
苹果APP启动,分为两个过程:系统dylib动态链接库 app的main函数启动过程. main函数过程直接对iOS开发者.这里备忘的dylib过程: 一.dyld加载到虚拟内存 1. loa ...
- [daily] 内存越界的分析与定位
valgrind 自不必说 1. Address Sanitize 很好有,只需要在gcc编译的时候,加上选项 -fsanitize=address 它的工程:https://github.com/ ...
- =[Mathematics] 数学主题
https://www.douban.com/group/maths/ 圆锥体体积公式的证明