Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Leet Code] 1148. Article Views I

์ธ” 2023. 10. 21. 15:52

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ๋ฆฌํŠธ์ฝ”๋“œ 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