[LeetCode Hard] 262. Trips and Users
·
SQL 문제 풀이
테이블 정보 문제 The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day. Write a solution to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03". Round Cancellation Rate to two d..
[프로그래머스 Level 4] 자동차 대여 기록 별 대여 금액 구하기
·
SQL 문제 풀이
테이블 정보  문제CAR_RENTAL_COMPANY_CAR 테이블과 CAR_RENTAL_COMPANY_RENTAL_HISTORY 테이블과 CAR_RENTAL_COMPANY_DISCOUNT_PLAN 테이블에서 자동차 종류가 '트럭'인 자동차의 대여 기록에 대해서 대여 기록 별로 대여 금액(컬럼명: FEE)을 구하여 대여 기록 ID와 대여 금액 리스트를 출력하는 SQL문을 작성해주세요. 결과는 대여 금액을 기준으로 내림차순 정렬하고, 대여 금액이 같은 경우 대여 기록 ID를 기준으로 내림차순 정렬해주세요.   예시  주의 사항FEE의 경우 예시처럼 정수부분만 출력되어야 합니다.  문제 풀이 1 (MySQL)데이터 타입을 꼼꼼히 살펴보지 않으면 어떻게 되는지 느끼게 해준 문제이다.아래 코드는 답은 맞았으나 문..
[프로그래머스 Level 4] 우유와 요거트가 담긴 장바구니
·
SQL 문제 풀이
테이블 정보 문제데이터 분석 팀에서는 우유(Milk)와 요거트(Yogurt)를 동시에 구입한 장바구니가 있는지 알아보려 합니다. 우유와 요거트를 동시에 구입한 장바구니의 아이디를 조회하는 SQL 문을 작성해주세요. 이때 결과는 장바구니의 아이디 순으로 나와야 합니다.  결과 예시  정답 코드 1 (MySQL)SELECT CART_IDFROM CART_PRODUCTSWHERE NAME IN ('Milk', 'Yogurt')GROUP BY CART_IDHAVING COUNT(DISTINCT NAME) >= 2ORDER BY CART_ID ASC;  문제 풀이 1Level 4라고 하기에는 생각보다 문제가 쉽게 풀렸다.나만 그렇게 느낀 게 아닌 건지 정답률이 70%나 된다...위 코드는 상품 이름이 'Milk'..
[LeetCode Hard] 601. Human Traffic of Stadium
·
SQL 문제 풀이
이번 문제는 개인적으로 많이 어려웠던 문제였다...ㅜ다른 사람들의 풀이를 보니 LEAD()와 LAG()를 이용한 문제 풀이가 있었는데솔직히 이번 문제를 풀면서 저런 함수가 있다는걸 처음 알았다꾸준히 복습하면서 내껄로 만들어야지... 테이블 정보  문제Write a solution to display the records with three or more rows with consecutive id's, and the number of people is greater than or equal to 100 for each. Return the result table ordered by visit_date in ascending order. The result format is in the following ..
[LeetCode Medium] 1341. Movie Rating
·
SQL 문제 풀이
테이블 정보  문제Write a solution to:Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.  결과 예시  정답 코드 (MySQL)(SELECT u.name AS resultsFROM Users uJOIN MovieRating mrON u.user_id = mr...
[LeetCode Hard] 185. Department Top Three Salaries
·
SQL 문제 풀이
테이블 정보 문제 A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department. Write a solution to find the employees who are high earners in each of the departments. Return the result table in any order. The result format is in the followi..
[LeetCode Medium] 550. Game Play Analysis IV
·
SQL 문제 풀이
테이블 정보  문제Write a solution to report the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.  결과 예시  정답 코드 (MySQL)WITH check_login AS ..
[프로그래머스 Level 4] 입양 시각 구하기 (2)
·
SQL 문제 풀이
테이블 정보 문제보호소에서는 몇 시에 입양이 가장 활발하게 일어나는지 알아보려 합니다. 0시부터 23시까지, 각 시간대별로 입양이 몇 건이나 발생했는지 조회하는 SQL문을 작성해주세요. 이때 결과는 시간대 순으로 정렬해야 합니다.  결과 예시  문제 풀이 (MySQL)SET @HOUR = -1;SELECT (@HOUR := @HOUR + 1) AS HOUR, (SELECT COUNT(HOUR(B.DATETIME)) FROM ANIMAL_OUTS B WHERE @HOUR = HOUR(B.DATETIME) ) AS COUNTFROM ANIMAL_OUTS ALIMIT 24; 위에 예시를 보다시피 7시부터 데이터가 존재한다.그러므로 단순히 HOUR(DATET..