From 9b2cacc835ba5bd68a7486098ffe3d211d3c59ab Mon Sep 17 00:00:00 2001 From: yanglbme Date: Tue, 4 Jul 2023 15:10:33 +0800 Subject: [PATCH] feat: add sql solution to lc problem: No.1919 No.1919.Leetcodify Similar Friends --- .../1919.Leetcodify Similar Friends/README.md | 10 +++++++++- .../1919.Leetcodify Similar Friends/README_EN.md | 10 +++++++++- .../1919.Leetcodify Similar Friends/Solution.sql | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md index 01970f3e7e26b..151ccbf15989f 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md @@ -106,7 +106,15 @@ Friendship table: ```sql - +# Write your MySQL query statement below +SELECT DISTINCT user1_id, user2_id +FROM + Friendship AS f + LEFT JOIN Listens AS l1 ON user1_id = l1.user_id + LEFT JOIN Listens AS l2 ON user2_id = l2.user_id +WHERE l1.song_id = l2.song_id AND l1.day = l2.day +GROUP BY 1, 2, l1.day +HAVING count(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md index bd41f41bce53c..223e20ab617db 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md @@ -100,7 +100,15 @@ Users 2 and 5 are friends and listened to songs 10, 11, and 12, but they did not ### **SQL** ```sql - +# Write your MySQL query statement below +SELECT DISTINCT user1_id, user2_id +FROM + Friendship AS f + LEFT JOIN Listens AS l1 ON user1_id = l1.user_id + LEFT JOIN Listens AS l2 ON user2_id = l2.user_id +WHERE l1.song_id = l2.song_id AND l1.day = l2.day +GROUP BY 1, 2, l1.day +HAVING count(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql b/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql new file mode 100644 index 0000000000000..76ab3963271e6 --- /dev/null +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql @@ -0,0 +1,9 @@ +# Write your MySQL query statement below +SELECT DISTINCT user1_id, user2_id +FROM + Friendship AS f + LEFT JOIN Listens AS l1 ON user1_id = l1.user_id + LEFT JOIN Listens AS l2 ON user2_id = l2.user_id +WHERE l1.song_id = l2.song_id AND l1.day = l2.day +GROUP BY 1, 2, l1.day +HAVING count(DISTINCT l1.song_id) >= 3;