개인활동(107)
-
[LeetCode/MySQL50] 577. Employee Bonus
ProblemSolutionselect E.name, B.bonusfrom Employee as Eleft join Bonus as B on E.empID = B.empIDwhere B.bonus Null값도 포함 시켜야 하기 때문에 where 절에서 is null을 활용해주기맨날 이 부분을 까먹는 것 같다
2025.03.10 -
[LeetCode/MySQL50] 1661. Average Time of Process per Machine
ProblemSolutionselect tb1.machine_id, round(avg(tb2.timestamp - tb1.timestamp), 3) processing_timefrom Activity tb1join Activity tb2 on tb2.machine_id = tb1.machine_id and tb1.process_id = tb2.process_idwhere tb1.activity_type = "start" and tb2.activity_type = "end"group by tb1.machine_id; 계속 답이 제대로 안뜨길래 뭐지.. 하고 있었는데 tb2.activity_type이 아니라 tb2.process_id로 조건을 작성해놔서 답이 제대로 안나왔던 것이였다.. 먼저 tb1을 기준으..
2025.02.03 -
[LeetCode/MySQL50] 197. Rising Temperature
ProblemSolutionselect today.id from Weather todaycross join Weather yesterdaywhere datediff(today.recordDate, yesterday.recordDate) = 1 and today.temperature > yesterday.temperature; 이 문제를 풀며 가장 어려웠던 부분은 하루차이가 나는 것을 어떻게 파악할 것인가? 이와 관련한 함수로 datediff라는 것을 알게 되었다datediff는 두 날짜를 입력받아 몇일 차이나는지 반환해주는 함수로 바로 전날이라는 것을 확인하기 위해서는 return 값이 1이 나와야 할 것이다. 이 사실을 활용해 어제와 오늘의 기온을 비교하여 id를 반환하면 해결 할 수 있는 것
2025.01.28 -
[LeetCode/MySQL50] 1581. Customer Who Visited but Did Not Make Any Transactions
ProblemSolution# Write your MySQL query statement belowselect v.customer_id, count(v.customer_id) as count_no_transfrom Visits vleft outer join Transactions t on v.visit_id = t.visit_idwhere t.transaction_id is nullgroup by v.customer_id; - group by를 통해 customer_id별 aggregation- left outer join을 활용해 Transaction이 생성되지 않은 id를 살려둘 수 있도록 함- join 후 transaction_id가 null값인 경우만 추출
2025.01.22 -
[LeetCode/MySQL50] 1068. Product Sales Analysis I
ProblemSolution# Write your MySQL query statement belowselect Product.product_name, Sales.year, Sales.pricefrom Salesinner join Product on Sales.product_id = Product.product_id; 여기서는 그냥 join을 사용해도 상관 없음
2025.01.14 -
[LeetCode/MySQL50] 1378. Replace Employee ID With The Unique Identifier
ProblemSolutionSELECT eu.unique_id, e.nameFROM Employees eLEFT JOIN EmployeeUNI euON e.id = eu.id;
2025.01.13 -
[LeetCode/MySQL50] 1683. Invalid Tweets
ProblemSolution# Write your MySQL query statement belowSelect tweet_id from Tweets where length(content) > 15;
2025.01.13 -
[LeetCode/MySQL50] 1148. Article Views I
ProblemSolution# Write your MySQL query statement belowselect distinct author_id id from Viewswhere author_id = viewer_id order by id ASC; MySQL Select문 중복 제거 : DISTINCTMySQL Select문 컬럼 명 재명명 : SELECT real_column_name (AS) change_name ... 정렬ASC : 오름차순DESC : 내림차순
2025.01.12 -
[LeetCode/MySQL50] 595. Big Countries
ProblemSolution# Write your MySQL query statement belowselect name, population, area from Worldwhere area >= 3000000 or population >= 25000000;
2025.01.12 -
[LeetCode/MySQL50] 584. Find Customer Referee
Problem Solution# Write your MySQL query statement belowselect name from Customerwhere referee_id != 2 or referee_id is null; MySQL에서 다르다는 표현은 != 를 사용하는 방법도 있지만, 를 사용하는 방법도 있다!
2025.01.11