You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can use self-join to compare each row in the `Weather` table with its previous row. If the temperature is higher and the date difference is one day, then it is the result we are looking for.
60
+
57
61
<!-- tabs:start -->
58
62
59
63
### **SQL**
@@ -68,13 +72,12 @@ FROM
68
72
```
69
73
70
74
```sql
71
-
SELECT
72
-
w2.idAS Id
75
+
# Write your MySQL query statement below
76
+
SELECTw1.id
73
77
FROM
74
-
weather AS w1
75
-
JOIN weather AS w2 ON DATE_ADD( w1.recordDate, INTERVAL 1 DAY) =w2.recordDate
76
-
WHERE
77
-
w1.temperature<w2.temperature
78
+
Weather AS w1
79
+
JOIN Weather AS w2
80
+
ON SUBDATE(w1.recordDate, 1) =w2.recordDateANDw1.temperature>w2.temperature;
Copy file name to clipboardExpand all lines: solution/0500-0599/0584.Find Customer Referee/README_EN.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,10 @@ Customer table:
55
55
56
56
## Solutions
57
57
58
+
**Solution 1: Conditional Filtering**
59
+
60
+
We can directly filter out the customer names whose `referee_id` is not `2`. Note that the customers whose `referee_id` is `NULL` should also be filtered out.
61
+
58
62
<!-- tabs:start -->
59
63
60
64
### **SQL**
Collapse file: solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md
Copy file name to clipboardExpand all lines: solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,33 +87,36 @@ As we can see, users with IDs 30 and 96 visited the mall one time without making
87
87
88
88
## Solutions
89
89
90
+
**Solution 1: Subquery + Grouping**
91
+
92
+
We can use a subquery to first find all `visit_id`s that have not made any transactions, and then group by `customer_id` to count the number of times each customer has not made any transactions.
93
+
94
+
**Solution 2: Left Join + Grouping**
95
+
96
+
We can also use a left join to join the `Visits` table and the `Transactions` table on `visit_id`, and then filter out the records where `amount` is `NULL`. After that, we can group by `customer_id` to count the number of times each customer has not made any transactions.
97
+
90
98
<!-- tabs:start -->
91
99
92
100
### **SQL**
93
101
94
102
<!-- 这里可写当前语言的特殊实现逻辑 -->
95
103
96
104
```sql
97
-
SELECT
98
-
customer_id,
99
-
COUNT(*) AS count_no_trans
105
+
# Write your MySQL query statement below
106
+
SELECT customer_id, COUNT(1) AS count_no_trans
100
107
FROM Visits
101
-
WHERE
102
-
visit_id NOT IN (
103
-
SELECT visit_id
104
-
FROM Transactions
105
-
)
106
-
GROUP BY customer_id;
108
+
WHERE visit_id NOT IN (SELECT visit_id FROM Transactions)
109
+
GROUP BY1;
107
110
```
108
111
109
112
```sql
110
113
# Write your MySQL query statement below
111
114
SELECT customer_id, COUNT(1) AS count_no_trans
112
115
FROM
113
-
VisitsAS v
114
-
LEFT JOIN Transactions AS t ONv.visit_id=t.visit_id
116
+
Visits
117
+
LEFT JOIN Transactions USING (visit_id)
115
118
WHERE amount IS NULL
116
-
GROUP BYcustomer_id;
119
+
GROUP BY1;
117
120
```
118
121
119
122
<!-- tabs:end -->
Collapse file: solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/Solution.sql
Copy file name to clipboardExpand all lines: solution/1600-1699/1683.Invalid Tweets/README_EN.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,14 @@ Tweet 2 has length = 32. It is an invalid tweet.
50
50
51
51
## Solutions
52
52
53
+
**Solution 1: Using `CHAR_LENGTH` Function**
54
+
55
+
The `CHAR_LENGTH()` function returns the length of a string, where Chinese characters, numbers, and letters are all counted as 1ドル$ byte.
56
+
57
+
The `LENGTH()` function returns the length of a string, where under utf8 encoding, Chinese characters are counted as 3ドル$ bytes, while numbers and letters are counted as 1ドル$ byte; under gbk encoding, Chinese characters are counted as 2ドル$ bytes, while numbers and letters are counted as 1ドル$ byte.
58
+
59
+
For this problem, we can directly use the `CHAR_LENGTH` function to get the length of the string, and filter out the tweet IDs with a length greater than 15ドル$.
0 commit comments