본문 바로가기

취준/코팅 테스트20

[LeetCode] - 1890. The Latest Login in 2020 문제 Write a solution to report the latest login for all users in the year 2020. Do not include the users who did not login in 2020. Return the result table in any order. The result format is in the following example. 문제 풀이 SELECT user_id, MAX(time_stamp) AS last_stamp FROM Logins WHERE time_stamp BETWEEN '2020-01-01 00:00:00' AND '2020-12-31 23:59:59' GROUP BY user_id 1. 2020년 로그인을 기록한 사용자가 조건이므로.. 2024. 3. 29.
[LeetCode] - 1251. Average Selling Price 문제 Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places. Return the result table in any order. The result format is in the following example. 문제 풀이 SELECT p.product_id , IFNULL(ROUND(SUM(units*price) / SUM(units),2),0) AS average_price FROM Prices p LEFT JOIN UnitsSold u ON p.product_id = u.product_id AND u.purchase_date BETWEEN.. 2024. 3. 28.
[LeetCode] - 180. Consecutive Numbers 문제 Find all numbers that appear at least three times consecutively. Return the result table in any order. The result format is in the following example. 문제풀이 SELECT DISTINCT num AS ConsecutiveNums FROM ( SELECT num , LEAD(num,1) OVER (ORDER BY id) AS num_1_after , LEAD(num,2) OVER (ORDER BY id) AS num_2_after FROM Logs ) nums WHERE num = num_1_after AND num = num_2_after 1. LEAD() 윈도우 함수를 이용해서 다.. 2024. 3. 27.
[LeetCode] - 1527. Patients With a Condition 문제 Write a solution to find the patient_id, patient_name, and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix. Return the result table in any order. The result format is in the following example. 1-1 문제풀이 SELECT * FROM Patients WHERE conditions REGEXP '\\bDIAB1' 1-2 문제 풀이 SELECT patient_id, patient_name, conditions FROM Patients WHERE conditio.. 2024. 3. 26.