| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- funnel
- row_number
- 신입 데이터분석가
- 윈도우함수
- 그로스해킹
- LEFTJOIN
- MYSQL
- 데이터리안
- 윈도우 함수
- 누적합
- 린분석
- 프로그래머스
- Datarian
- 데이터분석
- regexp
- 독서
- 순위함수
- SQL
- pandas
- Retention
- rank
- leetcode
- dense_rank
- 서브쿼리
- 퍼널분석
- SolveSQL
- 리텐션
- advent of sql
- 취준
- python
- Today
- Total
목록leetcode (19)
데이터 분석
문제 Write a solution to find the sum of amounts for odd and even transactions for each day. If there are no odd or even transactions for a specific date, display as 0. Return the result table ordered by transaction_date in ascending order. 💡각 일자별로 amount 값이 홀수인 경우의 합, 짝수인 경우의 합을 집계하는 문제 SolutionSELECT transaction_date , IFNULL(SUM(CASE WHEN MOD(amount, 2) != 0 THEN amount END), 0) AS odd_su..
문제 Write a solution to find for each user, the join date and the number of orders they made as a buyer in 2019. 💡이 문제의 핵심은 JOIN과 LEFT JOIN의 특징을 정확히 알고, 적절한 조인 조건을 활용하는 것이다. SolutionSELECT u.user_id AS buyer_id , u.join_date , COUNT(CASE WHEN o.order_date LIKE '2019%' THEN o.order_id END) AS orders_in_2019 -- NULL은 COUNT 시 0FROM Users u LEFT JOIN Orders o ON u.user_id = o.buyer_idGROU..
문제 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. 'id'가 연속적인 세 개 이상의 행을 찾되, 각 행의 'people'값이 100 이상인 경우에 해당하는 레코드를 출력하는 문제이다. 💡연속적이라는 단서를 보면 self-join을 통해 접근해 보자! Solution (1) ✔️ Stadium 테이블을 셀프 조인하여 세 개의 연속된 id 확인SELECT *F..
문제Write a solution to report the Capital gain/loss for each stock. The Capital gain/loss of a stock is the total gain or loss after buying and selling the stock one or many times. Return the result table in any order. 주식에 대한 각 'Sell' 작업은 이전 날에 해당하는 'Buy' 작업이 반드시 존재한다. 이 점을 참고하여, 하나의 주식을 한 번 또는 여러 번 사고판 후의 총 이익 또는 손실을 계산한다. SolutionSELECT stock_name , SUM(CASE WHEN operation = 'Buy' then -p..
문제You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day). Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). average_amount should be rounded to two decimal places.Return the result table ordered by visited_on in ascending order. 고객이 매일 얼마나 지출했는지에 대한 7일 이동 평균을 계산하는..
문제 Write a solution to find the rank of the scores. The ranking should be calculated according to the following rules:The scores should be ranked from the highest to the lowest.If there is a tie between two scores, both should have the same ranking.After a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks. score 값을 기..
문제 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. 각 부서마다 top 3에 해당하는 급여를 받는 직원의 부서명, 이름, 급여를 조회하는 문제이다.단, 같은 급여가 반복되더라도 한 번만 계산해야 한..
문제 Find all numbers that appear at least three times consecutively. 연속 3번 이상 등장하는 num을 조회하는 문제이다. Solution✔️ 쿼리 1 : 셀프조인을 이용하여 해결SELECT DISTINCT l1.num AS ConsecutiveNumsFROM Logs l1JOIN Logs l2 ON l2.id = l1.id + 1JOIN Logs l3 ON l3.id = l2.id + 1WHERE l1.num = l2.num AND l1.num = l3.num ✅ Logs 테이블을 3번 사용하여, id를 기준으로 각각 다음 행과 그다음 행을 조인✅ 현재 행과 다음 행의 num 값이 동일하고, 현재 행과 다다음 행의 num 값도 동일한 경우를 만족하면..
문제 Write a solution to find the first login date for each player. 각 플레이어별 최초 로그인 날짜를 조회하는 문제이다. Solution✔️ 쿼리 1 : GROUP BY를 이용하여 해결SELECT player_id , MIN(event_date) AS first_loginFROM ActivityGROUP BY player_id✔️ 쿼리 2 : MIN()을 활용한 윈도우 함수를 이용하여 해결SELECT DISTINCT player_id , MIN(event_date) OVER(PARTITION BY player_id) AS first_loginFROM Activity ✔️ 쿼리 3 : ROW_NUMBER()을 활용한 윈도우 함수를 이용하여..
문제 Write a solution to report the products that were only sold in the first quarter of 2019. That is, between 2019-01-01 and 2019-03-31 inclusive. 2019년 1분기에만 팔린 상품을 조회하는 문제이다. Solution✔️ 쿼리 1SELECT product_id , product_nameFROM ProductWHERE product_id IN ( SELECT product_id FROM Sales GROUP BY product_id HAVING MIN(sale_date) >= '2019-01-01' AND MAX(sale_date) ✅ WHERE절에 서브쿼리를 ..