
๐ข ๋ณธ ํฌ์คํ ์ ํ์ฉ๋๋ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐ ์๋ฃ ์ถ์ฒ๋
๋ฆฌํธ์ฝ๋ Problems, https://leetcode.com/problemset/all/์์ ๋ฐํ๋๋ค.
โ๋ฌธ์
https://leetcode.com/problems/article-views-i/description/
Article Views I - LeetCode
Can you solve this real interview question? Article Views I - Table: Views +---------------+---------+ | Column Name | Type | +---------------+---------+ | article_id | int | | author_id | int | | viewer_id | int | | view_date | date | +---------------+---
leetcode.com
Table : Views

Write a solution to find all the authors that viewed at least one of their own articles.
Return the result table sorted by id in ascending order.
โฆ
โ ํ์ด
๋ฌธ์ ์๊ตฌ์ฌํญ
์์ ์ ๊ธฐ์ฌ๋ฅผ ์ต์ํ 1๋ฒ ์ด์ ๋ณธ ์๊ฐ์ id๋ฅผ ์ถ๋ ฅํด์ผํ๋ค.
WHERE์ ์ authior_id์ viewer_id๊ฐ ๋์ผํ์ฌ์ผ ํ๋ค ์กฐ๊ฑดยน์ ์ฃผ๊ณ 1๋ฒ ์ด์ ๋ณธ ์๊ฐ์ฌ์ ๋ณธ ํ์๋ฅผ ์กฐ๊ฑด์ ์ถ๊ฐ๋ก ๋ฃ์ง ์์๋ค. ๋ง์ฝ 1๋ฒ๋ณด๋ค ๋ง์ nํ๋ผ๋ฉด 1์กฐ๊ฑด์ ๋ํ ์ง๊ณ ํ, nํ๋ฅผ ์ถฉ์กฑํ๋ ์ฌ๋์ ์ถ๋ ฅํด์ฃผ๋ ์ฟผ๋ฆฌ๋ฅผ ๋ณ๋๋ก ๋ง๋ค์ด์ฃผ์ด์ผ ํ ๊ฒ ๊ฐ๋ค.
SELECT DISTINCT author_id AS id
FROM Views
WHERE author_id = viewer_id
ORDER BY 1;
๐โโ๏ธ ๋ฌธ์ ํ์ด์ mysql ์ฟผ๋ฆฌ ํจ์จ์ฑ ๋์ด๊ธฐ ๋ฑ ํฌ์คํ ์ ๋ํ ์๊ฒฌ ๋ฐ ๊ธฐ์ ์กฐ์ธ ๋๊ธ ๋ชจ๋ ํ์ํฉ๋๋ค.
'Growth ๐ณ > Practice ๐ป' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leet Code] 1873. Calculate Special Bonus (0) | 2023.10.24 |
---|---|
[Leet Code] 1633. Percentage of Users Attended a Contest (0) | 2023.10.23 |
[Leet Code] 1407. Top Travellers (1) | 2023.10.20 |
[Leet Code] 1251. Average Selling Price (0) | 2023.10.18 |
[Leet Code] 1280. Students and Examinations (0) | 2023.10.17 |