586. Customer Placing the Largest Number of Orders

思路:原题只有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))


阅读更多

Largest prime number ever is found

12-03

http://www.newscientist.com/news/news.jsp?id=ns99994438rnrnLargest prime number ever is found rn rn rn15:11 02 December 03 rn rnNewScientist.com news service rn rnA 26-year-old graduate student in the US has made mathematical history by discovering the largest known prime number.rnrnThe new number is 6,320,430 digits long. It took just over two years to find using a distributed network of more than 200,000 computers.rnrnMichael Shafer a chemical engineering student at Michigan State University used his office computer to contribute spare processing power to the Great Internet Mersenne Prime Search (GIMPS). The project has more than 60,000 volunteers from all over the world taking part.rnrn"I had just finished a meeting with my advisor when I saw the computer had found the new prime," Shafer says. "After a short victory dance, I called up my wife and friends involved with GIMPS to share the great news." rnrnPrime numbers are positive integers that can only be divided by themselves and one. Mersenne primes are an especially rare type of prime that take the form 2 p-1, where p is also a prime number. The new number can be represented as 220,996,011-1. It is only the 40th Mersenne prime to have ever been found.rnrnrnBuilding blocks rnrnrnMersenne primes were first discussed by Euclid in 350 BC and have been central to the branch of mathematics known as number theory ever since. They are named after a 17th century French monk who first came up with an important conjecture about which values of p would yield a prime.rnrnPrimes are the building blocks of all positive numbers. They have practical uses too, for example by providing a way of exchanging the cryptographic keys that keep internet communications secure from eavesdropping. However, despite their significance, mathematicians do not understand the way prime numbers are distributed making it very difficult to identify new primes.rnrnMarcus du Sautoy, a mathematician at Oxford University and author of The Music of the Primes, says the discovery is unlikely to add much to our understanding of the way primes are distributed but is still significant. rnrn"It's a really good measure of what our computational capabilities are," he told New Scientist. "It's a really fun project. Everyone gets a different bit of the number universe to look at. It's a bit like the lottery."rnrn The World's No.1 Science & Technology News Service rn rn rn rnLargest prime number ever is found rn rn rn15:11 02 December 03 rn rnNewScientist.com news service rn rnA 26-year-old graduate student in the US has made mathematical history by discovering the largest known prime number.rnrnThe new number is 6,320,430 digits long. It took just over two years to find using a distributed network of more than 200,000 computers.rnrnMichael Shafer a chemical engineering student at Michigan State University used his office computer to contribute spare processing power to the Great Internet Mersenne Prime Search (GIMPS). The project has more than 60,000 volunteers from all over the world taking part.rnrn"I had just finished a meeting with my advisor when I saw the computer had found the new prime," Shafer says. "After a short victory dance, I called up my wife and friends involved with GIMPS to share the great news." rnrnPrime numbers are positive integers that can only be divided by themselves and one. Mersenne primes are an especially rare type of prime that take the form 2 p-1, where p is also a prime number. The new number can be represented as 220,996,011-1. It is only the 40th Mersenne prime to have ever been found.rnrnrnBuilding blocks rnrnrnMersenne primes were first discussed by Euclid in 350 BC and have been central to the branch of mathematics known as number theory ever since. They are named after a 17th century French monk who first came up with an important conjecture about which values of p would yield a prime.rnrnPrimes are the building blocks of all positive numbers. They have practical uses too, for example by providing a way of exchanging the cryptographic keys that keep internet communications secure from eavesdropping. However, despite their significance, mathematicians do not understand the way prime numbers are distributed making it very difficult to identify new primes.rnrnMarcus du Sautoy, a mathematician at Oxford University and author of The Music of the Primes, says the discovery is unlikely to add much to our understanding of the way primes are distributed but is still significant. rnrn"It's a really good measure of what our computational capabilities are," he told New Scientist. "It's a really fun project. Everyone gets a different bit of the number universe to look at. It's a bit like the lottery."rnrnMathematical curiosity rn rnThe GIMPS project uses a central computer server and free software to coordinate the activity of all its contributors. Contributing machines are each allocated different prime number candidates to test.rnrnSome people contribute to GIMPS out of mathematical curiosity or to test their computer hardware, while others just hope to go down in history as the discoverer of a massive prime. There is also a financial incentive with the Electronic Frontier Foundation, a non-profit US group, offering a $100,000 prize for the discovery of the first prime with 10 million digits.rnrnShafer's discovery was made on 17 November but it was not independently verified until now. "It's humbling to see so many people of varied lands, ages and vocations volunteering for this fun and amazing project," says Scott Kurowski, whose company Entropia manages the GIMPS server. rnrn"There are more primes out there," adds George Woltman, who started the GIMPS project in 1996. "And anyone with an internet-connected computer can participate."rn rn rnWill Knightrnrn

没有更多推荐了,返回首页