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

Commit 81e5b16

Browse files
feat: add sql solutions to lc problems (doocs#1121)
* No.1990.Count the Number of Experiments * No.2020.Number of Accounts That Did Not Stream * No.2051.The Category of Each Member in the Store * No.2066.Account Balance * No.2084.Drop Type 1 Orders for Customers With Type 0 Orders * No.2112.The Airport With the Most Traffic
1 parent 18dbf9d commit 81e5b16

File tree

25 files changed

+301
-33
lines changed

25 files changed

+301
-33
lines changed

‎.prettierrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
3434
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
3535
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
36+
"solution/2000-2099/2066.Account Balance/Solution.sql",
3637
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
3738
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql"
3839
],

‎solution/0100-0199/0192.Word Frequency/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ day 1
5050
<!-- 这里可写当前语言的特殊实现逻辑 -->
5151

5252
```sh
53-
53+
# Read from the file words.txt and output the word frequency list to stdout.
54+
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print 2,ドル 1ドル}'
5455
```
5556

5657
<!-- tabs:end -->

‎solution/0100-0199/0192.Word Frequency/README_EN.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ day 1
4646
### **Bash**
4747

4848
```sh
49-
49+
# Read from the file words.txt and output the word frequency list to stdout.
50+
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print 2,ドル 1ドル}'
5051
```
5152

5253
<!-- tabs:end -->
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
#!/usr/bin/env bash
2-
3-
# NF是当前行的field字段数;NR是正在处理的当前行数。
4-
awk '{
5-
for(i=1;i<=NF;i++){
6-
res[$i]++
7-
}
8-
}
9-
END{
10-
for(k in res){
11-
print k,res[k]
12-
}
13-
}' words.txt | sort -nr -k2
14-
15-
#or:
16-
17-
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{print 2ドル" "1ドル}'
1+
# Read from the file words.txt and output the word frequency list to stdout.
2+
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print 2,ドル 1ドル}'

‎solution/1900-1999/1990.Count the Number of Experiments/README.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,33 @@ Experiments table:
7979
<!-- 这里可写当前语言的特殊实现逻辑 -->
8080

8181
```sql
82-
82+
# Write your MySQL query statement below
83+
WITH
84+
P AS (
85+
SELECT 'Android' AS platform
86+
UNION
87+
SELECT 'IOS'
88+
UNION
89+
SELECT 'Web'
90+
),
91+
Exp AS (
92+
SELECT 'Reading' AS experiment_name
93+
UNION
94+
SELECT 'Sports'
95+
UNION
96+
SELECT 'Programming'
97+
),
98+
T AS (
99+
SELECT *
100+
FROM
101+
P,
102+
Exp
103+
)
104+
SELECT platform, experiment_name, count(experiment_id) AS num_experiments
105+
FROM
106+
T AS t
107+
LEFT JOIN Experiments USING (platform, experiment_name)
108+
GROUP BY 1, 2;
83109
```
84110

85111
<!-- tabs:end -->

‎solution/1900-1999/1990.Count the Number of Experiments/README_EN.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,33 @@ On the platform &quot;Web&quot;, we had two &quot;Reading&quot; experiments and
7171
### **SQL**
7272

7373
```sql
74-
74+
# Write your MySQL query statement below
75+
WITH
76+
P AS (
77+
SELECT 'Android' AS platform
78+
UNION
79+
SELECT 'IOS'
80+
UNION
81+
SELECT 'Web'
82+
),
83+
Exp AS (
84+
SELECT 'Reading' AS experiment_name
85+
UNION
86+
SELECT 'Sports'
87+
UNION
88+
SELECT 'Programming'
89+
),
90+
T AS (
91+
SELECT *
92+
FROM
93+
P,
94+
Exp
95+
)
96+
SELECT platform, experiment_name, count(experiment_id) AS num_experiments
97+
FROM
98+
T AS t
99+
LEFT JOIN Experiments USING (platform, experiment_name)
100+
GROUP BY 1, 2;
75101
```
76102

77103
<!-- tabs:end -->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
P AS (
4+
SELECT 'Android' AS platform
5+
UNION
6+
SELECT 'IOS'
7+
UNION
8+
SELECT 'Web'
9+
),
10+
Exp AS (
11+
SELECT 'Reading' AS experiment_name
12+
UNION
13+
SELECT 'Sports'
14+
UNION
15+
SELECT 'Programming'
16+
),
17+
T AS (
18+
SELECT *
19+
FROM
20+
P,
21+
Exp
22+
)
23+
SELECT platform, experiment_name, count(experiment_id) AS num_experiments
24+
FROM
25+
T AS t
26+
LEFT JOIN Experiments USING (platform, experiment_name)
27+
GROUP BY 1, 2;

‎solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ Streams table:
8989
<!-- 这里可写当前语言的特殊实现逻辑 -->
9090

9191
```sql
92-
92+
# Write your MySQL query statement below
93+
SELECT count(DISTINCT sub.account_id) AS accounts_count
94+
FROM
95+
Subscriptions AS sub
96+
LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id
97+
WHERE
98+
year(start_date) <= 2021
99+
AND year(end_date) >= 2021
100+
AND (year(stream_date) != 2021 OR stream_date > end_date);
93101
```
94102

95103
<!-- tabs:end -->

‎solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ User 11 did not subscribe in 2021.
8686
### **SQL**
8787

8888
```sql
89-
89+
# Write your MySQL query statement below
90+
SELECT count(DISTINCT sub.account_id) AS accounts_count
91+
FROM
92+
Subscriptions AS sub
93+
LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id
94+
WHERE
95+
year(start_date) <= 2021
96+
AND year(end_date) >= 2021
97+
AND (year(stream_date) != 2021 OR stream_date > end_date);
9098
```
9199

92100
<!-- tabs:end -->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write your MySQL query statement below
2+
SELECT count(DISTINCT sub.account_id) AS accounts_count
3+
FROM
4+
Subscriptions AS sub
5+
LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id
6+
WHERE
7+
year(start_date) <= 2021
8+
AND year(end_date) >= 2021
9+
AND (year(stream_date) != 2021 OR stream_date > end_date);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /