|
| 1 | +# [2994. Friday Purchases II](https://leetcode.cn/problems/friday-purchases-ii) |
| 2 | + |
| 3 | +[English Version](/solution/2900-2999/2994.Friday%20Purchases%20II/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>Table: <code>Purchases</code></p> |
| 10 | + |
| 11 | +<pre> |
| 12 | ++---------------+------+ |
| 13 | +| Column Name | Type | |
| 14 | ++---------------+------+ |
| 15 | +| user_id | int | |
| 16 | +| purchase_date | date | |
| 17 | +| amount_spend | int | |
| 18 | ++---------------+------+ |
| 19 | +(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table. |
| 20 | +purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates. |
| 21 | +Each row contains user id, purchase date, and amount spend. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. If there are <strong>no</strong> purchases on a particular <strong>Friday of a week</strong>, it will be considered as <code>0</code>.</p> |
| 25 | + |
| 26 | +<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p> |
| 27 | + |
| 28 | +<p>The result format is in the following example.</p> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong class="example">Example 1:</strong></p> |
| 32 | + |
| 33 | +<pre> |
| 34 | +<strong>Input:</strong> |
| 35 | +Purchases table: |
| 36 | ++---------+---------------+--------------+ |
| 37 | +| user_id | purchase_date | amount_spend | |
| 38 | ++---------+---------------+--------------+ |
| 39 | +| 11 | 2023-11-07 | 1126 | |
| 40 | +| 15 | 2023-11-30 | 7473 | |
| 41 | +| 17 | 2023-11-14 | 2414 | |
| 42 | +| 12 | 2023-11-24 | 9692 | |
| 43 | +| 8 | 2023-11-03 | 5117 | |
| 44 | +| 1 | 2023-11-16 | 5241 | |
| 45 | +| 10 | 2023-11-12 | 8266 | |
| 46 | +| 13 | 2023-11-24 | 12000 | |
| 47 | ++---------+---------------+--------------+ |
| 48 | +<strong>Output:</strong> |
| 49 | ++---------------+---------------+--------------+ |
| 50 | +| week_of_month | purchase_date | total_amount | |
| 51 | ++---------------+---------------+--------------+ |
| 52 | +| 1 | 2023-11-03 | 5117 | |
| 53 | +| 2 | 2023-11-10 | 0 | |
| 54 | +| 3 | 2023-11-17 | 0 | |
| 55 | +| 4 | 2023-11-24 | 21692 | |
| 56 | ++---------------+---------------+--------------+ |
| 57 | +<strong>Explanation:</strong> |
| 58 | +- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03. |
| 59 | +- For the second week of November 2023, there were no transactions on Friday, 2023-11-10, resulting in a value of 0 in the output table for that day. |
| 60 | +- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17, reflected as 0 in the output table for that specific day. |
| 61 | +- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692. |
| 62 | +Output table is ordered by week_of_month in ascending order.</pre> |
| 63 | + |
| 64 | +## 解法 |
| 65 | + |
| 66 | +<!-- 这里可写通用的实现逻辑 --> |
| 67 | + |
| 68 | +<!-- tabs:start --> |
| 69 | + |
| 70 | +### **SQL** |
| 71 | + |
| 72 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 73 | + |
| 74 | +```sql |
| 75 | + |
| 76 | +``` |
| 77 | + |
| 78 | +<!-- tabs:end --> |
0 commit comments