Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a62bc5

Browse files
add 1596
1 parentb63d865 commit3a62bc5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ _If you like this project, please leave me a star._ ★
10961096
|1633|[Percentage of Users Attended a Contest](https://leetcode.com/problems/percentage-of-users-attended-a-contest/)|[Solution](../master/database/_1633.sql)|| Easy|
10971097
|1623|[All Valid Triplets That Can Represent a Country](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country/)|[Solution](../master/database/_1623.sql)|| Easy|
10981098
|1607|[Sellers With No Sales](https://leetcode.com/problems/sellers-with-no-sales/)|[Solution](../master/database/_1607.sql)|| Easy|
1099+
|1596|[The Most Frequently Ordered Products for Each Customer](https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer/)|[Solution](../master/database/_1596.sql)|| Medium|
10991100
|1571|[Warehouse Manager](https://leetcode.com/problems/warehouse-manager/)|[Solution](../master/database/_1571.sql)|| Easy|
11001101
|1587|[Bank Account Summary II](https://leetcode.com/problems/bank-account-summary-ii/)|[Solution](../master/database/_1587.sql)|| Easy|
11011102
|1581|[Customer Who Visited but Did Not Make Any Transactions](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/)|[Solution](../master/database/_1581.sql)|| Easy|

‎database/_1596.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--credit: https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer/discuss/861257/simple-and-easy-solution-using-window-function
2+
3+
select customer_id, product_id, product_namefrom
4+
(
5+
selecto.customer_id,o.product_id,p.product_name,
6+
rank() over (partition by customer_idorder bycount(o.product_id)desc)as ranking
7+
from Orders o
8+
join Products p
9+
ono.product_id=p.product_id
10+
group by customer_id, product_id
11+
) tmp
12+
where ranking=1
13+
order by customer_id, product_id

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp