♟️ 알고리즘/Leetcode 17

[MySQL][Leet Code] 197. Rising Temperature (Easy)

https://leetcode.com/problems/rising-temperature/description/?envType=study-plan-v2&envId=top-sql-50 🗒️SQL 코드 풀이 SELECT idFROM Weather W1 INNER JOIN ( SELECT DATE_ADD(recordDate, INTERVAL 1 DAY) recordDate2, temperature FROM Weather ) W2 ON W1.recordDate = W2.recordDate2WHERE W1.temperature - W2.temperature > 0 1. 문제에서 요구하는 것은 간단하다. 전날과 비교해서 기온이 떨어지는 id를 출력하는 것이다. 2. ..

[MySQL][Leet Code] 1581. Customer Who Visited but Did Not Make Any Transactions (Easy)

https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 SELECT customer_id, COUNT(*) count_no_trans FROM Visits v LEFT JOIN Transactions t ON v.visit_id = t.visit_idWHERE t.visit_id IS NULLGROUP BY customer_id 1. LEFT JOIN을 하고 , visit_id 컬럼이 2개가 나오는데, 그 중 Transactions의 컬럼의 visit_id 의 NULL 값을 조회한다. 2. 이후 ..

[MySQL][Leet Code] 1378. Replace Employee ID With The Unique Identifier (Easy)

https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT unique_id , nameFROM Employees e LEFT JOIN EmployeeUNI eu ON e.id = eu.id 1. 간단한 JOIN 문제로 먼저 가져올 테이블 Employee를 선택한다. 2. 이후 EmployeeUNI와 JOIN을 하는데, id를 기준으로 해준다.  📌..

[MySQL][Leet Code] 1148. Article Views I (Easy)

https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT DISTINCT author_id AS id FROM ViewsWHERE author_id = viewer_idORDER BY id 1. 간단한 SQL 문제이다.  먼저 가져올 테이블 Views를 선택한다. 2. 이후 author_id와 viewer_id가 같은 조건을 걸어준다 . 3. 선택 할 컬럼은 author_id이로 Alias는 ..

[MySQL][Leet Code] 584. Find Customer Referee (Easy)

https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50🗒️SQL 코드 풀이 1SELECT nameFROM CustomerWHERE referee_id != 2 OR referee_id IS NULL 1. 간단한 SQL 문제이다.  Customer 테이블에서 referee_id가 2가 아닌 값을 찾아냄  2. 주의점은 referee_id에 NULL 값이 있는데, 이거 같은 경우 값이 아니기 때문에 같은 연산자로 못 찾음  3. 때문에 IS NULL 과 같은 방법으로 찾는다.  🗒️SQL 코드 풀이 2SELECT nameFROM CustomerWHERE COALESCE(r..