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

Appearance settings

Commit 0e79b7d

Browse filesBrowse files
committed
Update README.md
1 parent b44a460 commit 0e79b7d
Copy full SHA for 0e79b7d

File tree

1 file changed

+42
-1
lines changed
Filter options

1 file changed

+42
-1
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+42-1Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,46 @@ GROUP BY query_name
213213

214214
[1193. Monthly Transactions I](https://leetcode.com/problems/monthly-transactions-i/)
215215
```sql
216+
-- month, country, count(trans), total(amt), count(approved_trans), total(amt)
217+
SELECT DATE_FORMAT(trans_date, '%Y-%m') month, country,
218+
COUNT(state) trans_count,
219+
SUM(IF(state = 'approved', 1, 0)) approved_count,
220+
SUM(amount) trans_total_amount,
221+
SUM(IF(state = 'approved', amount, 0)) approved_total_amount
222+
FROM Transactions
223+
GROUP BY 1, 2
216224

217-
```
225+
-- OR
226+
SELECT DATE_FORMAT(trans_date, '%Y-%m') month, country,
227+
COUNT(state) trans_count,
228+
SUM(CASE WHEN state = 'approved' THEN 1 ELSE 0 END) approved_count,
229+
SUM(amount) trans_total_amount,
230+
SUM(CASE WHEN state = 'approved' THEN amount ELSE 0 END) approved_total_amount
231+
FROM Transactions
232+
GROUP BY 1, 2
233+
```
234+
235+
[1174. Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii/)
236+
```sql
237+
SELECT
238+
ROUND((COUNT(CASE WHEN d.order_date = d.customer_pref_delivery_date THEN 1 END) / COUNT(*)) * 100, 2) immediate_percentage
239+
FROM Delivery d
240+
WHERE d.order_date = (
241+
SELECT
242+
MIN(order_date)
243+
FROM Delivery
244+
WHERE customer_id = d.customer_id
245+
);
246+
247+
-- OR
248+
SELECT ROUND(AVG(temp.order_date=temp.customer_pref_delivery_date) * 100, 2) immediate_percentage
249+
FROM (
250+
SELECT *, RANK() OVER(partition by customer_id ORDER BY order_date) od
251+
FROM Delivery) temp
252+
WHERE temp.od = 1
253+
```
254+
255+
<!-- [550. Game Play Analysis IV](https://leetcode.com/problems/game-play-analysis-iv/)
256+
```sql
257+
258+
``` -->

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.