| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- dense_rank
- 데이터분석
- SQL
- 데이터리안
- SolveSQL
- 린분석
- MYSQL
- 윈도우 함수
- 리텐션
- 독서
- python
- leetcode
- advent of sql
- 취준
- 순위함수
- 퍼널분석
- rank
- 신입 데이터분석가
- Datarian
- 누적합
- 프로그래머스
- 서브쿼리
- 그로스해킹
- regexp
- funnel
- 윈도우함수
- row_number
- Retention
- pandas
- LEFTJOIN
- Today
- Total
목록SQL (62)
데이터 분석
문제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()을 활용한 윈도우 함수를 이용하여..
레스토랑의 요일별 VIP 문제 조건1. 요일별로 가장 높은 금액의 결제 내역을 출력2. 쿼리 결과는 테이블에 있는 모든 컬럼을 포함 Solution ✔️ 쿼리 1 : 다중 컬럼 서브쿼리를 이용하여 해결SELECT * FROM tipsWHERE (day, total_bill) IN ( SELECT day , MAX(total_bill) FROM tips GROUP BY day) ✅ 서브쿼리로 요일별 가장 높은 금액을 계산한다✅ 메인쿼리 WHERE절에 다중 컬럼 조건으로 서브쿼리 결과와 만족하는 행만 반환한다 ✔️ 쿼리 2 : ROW_NUMBER(), 윈도우 함수를 이용하여 해결SELECT total_bill , tip , sex , smoker , day ..
다음날도 서울숲의 미세먼지 농도는 나쁨 😢✔️0217 복습 문제 조건1. 당일의 미세먼지 농도보다 바로 다음날의 미세먼지 농도가 더 안 좋은 날을 출력2. 쿼리 결과는 당일, 다음날, 당일의 미세먼지 농도, 다음날의 미세먼지 농도 컬럼을 포함 Solution ✔️ 쿼리 1 : 셀프조인을 이용하여 해결SELECT m1.measured_at AS today , m2.measured_at AS next_day , m1.pm10 , m2.pm10 AS next_pm10FROM measurements m1 JOIN measurements m2 ON m2.measured_at = DATE_ADD(m1.measured_at, INTERVAL 1 DAY)WHERE m1.pm10 ✅ JOIN ..
문제 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절에 서브쿼리를 ..
문제 Write a solution to report the customer ids from the Customer table that bought all the products in the Product table. 모든 상품을 구매한 고객을 조회하는 문제이다. SolutionSELECT customer_idFROM CustomerGROUP BY customer_idHAVING COUNT(DISTINCT product_key) = (SELECT COUNT(product_key) FROM Product) ✅ 고객 id별 구매 이력이 있는 고유 상품 개수를 집계하여, 이것이 Product 테이블의 상품 개수와 동일한 경우를 만족하는 고객을 반환한다.