Skip to content

Commit 869806b

Browse files
authored
feat: add sql solution to lc problem: No.1892 (#1116)
No.1892.Page Recommendations II
1 parent 4801ec1 commit 869806b

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.github/workflows/clang-format-lint.yml

+10
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ jobs:
1010

1111
steps:
1212
- uses: actions/checkout@v3
13+
1314
- uses: DoozyX/clang-format-lint-action@v0.13
1415
with:
1516
source: '.'
1617
extensions: 'c,cpp,java'
1718
clangFormatVersion: 12
19+
inplace: True
20+
21+
- uses: EndBug/add-and-commit@v9
22+
with:
23+
committer_name: yanglbme
24+
committer_email: contact@yanglibin.info
25+
message: 'chore: format code with clang-format'
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}

solution/1800-1899/1892.Page Recommendations II/README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,24 @@ Likes 表:
127127
<!-- 这里可写当前语言的特殊实现逻辑 -->
128128

129129
```sql
130-
130+
# Write your MySQL query statement below
131+
WITH
132+
S AS (
133+
SELECT * FROM Friendship
134+
UNION
135+
SELECT user2_id, user1_id FROM Friendship
136+
)
137+
SELECT user1_id AS user_id, page_id, count(1) AS friends_likes
138+
FROM
139+
S AS s
140+
LEFT JOIN Likes AS l ON s.user2_id = l.user_id
141+
WHERE
142+
NOT EXISTS (
143+
SELECT 1
144+
FROM Likes AS l2
145+
WHERE user1_id = l2.user_id AND l.page_id = l2.page_id
146+
)
147+
GROUP BY user1_id, page_id;
131148
```
132149

133150
<!-- tabs:end -->

solution/1800-1899/1892.Page Recommendations II/README_EN.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,24 @@ You can recommend pages for users 2, 3, 4, and 5 using a similar process.
120120
### **SQL**
121121

122122
```sql
123-
123+
# Write your MySQL query statement below
124+
WITH
125+
S AS (
126+
SELECT * FROM Friendship
127+
UNION
128+
SELECT user2_id, user1_id FROM Friendship
129+
)
130+
SELECT user1_id AS user_id, page_id, count(1) AS friends_likes
131+
FROM
132+
S AS s
133+
LEFT JOIN Likes AS l ON s.user2_id = l.user_id
134+
WHERE
135+
NOT EXISTS (
136+
SELECT 1
137+
FROM Likes AS l2
138+
WHERE user1_id = l2.user_id AND l.page_id = l2.page_id
139+
)
140+
GROUP BY user1_id, page_id;
124141
```
125142

126143
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
S AS (
4+
SELECT * FROM Friendship
5+
UNION
6+
SELECT user2_id, user1_id FROM Friendship
7+
)
8+
SELECT user1_id AS user_id, page_id, count(1) AS friends_likes
9+
FROM
10+
S AS s
11+
LEFT JOIN Likes AS l ON s.user2_id = l.user_id
12+
WHERE
13+
NOT EXISTS (
14+
SELECT 1
15+
FROM Likes AS l2
16+
WHERE user1_id = l2.user_id AND l.page_id = l2.page_id
17+
)
18+
GROUP BY user1_id, page_id;

0 commit comments

Comments
 (0)