日誌2024-10-31 12:46
【Leetcode】1581. Customer Who Visited but Did Not Make Any Transactions作者:Chris
Visits表格屬性 | |
Column Name | Type |
visit_id | int |
customer_id | int |
Transactions表格屬性 | |
Column Name | Type |
transaction_id | int |
visit_id | int |
amount | int |
Visits | |
visit_id | customer_id |
1 | 23 |
2 | 9 |
4 | 30 |
5 | 54 |
6 | 96 |
7 | 54 |
8 | 54 |
Transactions | ||
transaction_id | visit_id | amount |
2 | 5 | 310 |
3 | 5 | 300 |
9 | 5 | 200 |
12 | 1 | 910 |
13 | 2 | 970 |
customer_id | count_no_trans |
54 | 2 |
30 | 1 |
96 | 1 |
個人理解 |
先用Left join語法將語法資料表合併,透過COUNT()計算出訂單總數,最後再進行分組 |
程式碼 |
select customer_id,count(visit_id) as count_no_trans from Visits left join Transactions using(visit_id) where transaction_id is null group by customer_id; |