전체 글 140

The Blunder

문제 풀이 링크: https://www.hackerrank.com/challenges/the-blunder/problem?isFullScreen=true The Blunder | HackerRankQuery the amount of error in Sam's result, rounded up to the next integer.www.hackerrank.com⌨️ The Blunder 문제 요약EMPLOYEES 테이블의 salary 컬럼을 기반으로실제 평균 월급: AVG(salary)잘못된 평균 월급: salary에서 숫자 0을 제거한 값으로 계산한 평균두 평균의 차이를 구하고 결과는 올림(CEIL) 해서 정수로 출력정답 풀이CEIL: 올림 처리 함수로, 소수점을 올림하여 정수로 반환CAST(REPLAC..

SQL 2025.05.05

Top Earners

문제 풀이 링크: https://www.hackerrank.com/challenges/earnings-of-employees/problem?isFullScreen=true Top Earners | HackerRankFind the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount).www.hackerrank.com💰 Top Earners 문제 요약Employee 테이블에서각 직원의 총 수입(total earnings) = salary * months그 중 최고 총 수입(max total earnings)을 구하고그 최고 수입을 받은 직원 ..

SQL 2025.05.05

Repeated Payments: Stripe SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/repeated-payments Stripe SQL Interview Question | DataLemurStripe SQL Interview Question: Write a query to count the repeated payments.datalemur.com🧾 중복 결제 탐지 문제 요약목적: 동일한 merchant, credit card, 결제 금액으로 10분 이내에 발생한 중복 결제 건수를 식별하고 개수 확인조건:merchant_id, credit_card_id, amount가 모두 같아야 함결제 시각 간격이 10분 이내여야 함중복된 결제에서 첫 번째 결제는 제외하고, 이후 건만 중복 결제로 간주예: 동일 조건으로 두 ..

SQL 2025.05.03

Card Launch Success: JPMorgan SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/card-launch-success JPMorgan Chase SQL Interview Question | DataLemurJPMorgan Chase SQL Interview Question: Write a query to find how many cards were launched in its launch month.datalemur.com💳 JPMorgan 신용카드 첫 달 발급량 조회 문제 요약목적: 신용카드별 출시 첫 달에 발급된 카드 수량 조회조건:출시 첫 달(launch month)은 해당 카드가 monthly_cards_issued 테이블에 처음 등장한 연·월각 카드의 출시 첫 달의 발급량만 집계 대상결과는 발급량 기..

SQL 2025.05.03

Department vs. Company Salary: FAANG SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/sql-department-company-salary-comparison FAANG SQL Interview Question | DataLemurFAANG SQL Interview Question: Write a query to compare the average salary of employees in each department to the company's average salary.datalemur.com💼 부서별 평균 급여 비교 문제 요약 목적: 2024년 3월에 대해 각 부서별 평균 급여가 회사 전체 평균 급여보다 높은지 / 낮은지 / 같은지 비교조건:비교 결과는 'higher', 'lower', 'same' 중 하나..

SQL 2025.04.30

3-Topping Pizzas: McKinsey SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/pizzas-topping-cost McKinsey SQL Interview Question | DataLemurMcKinsey SQL Interview Question: Write a query to calculate the cost of 3-topping pizzas.datalemur.com 🍕 3-토핑 피자 조합 비용 계산 문제 요약목적: 서로 다른 3개 토핑으로 만들 수 있는 모든 피자 조합에 대해 총 재료 비용을 계산하고 출력조건:토핑은 반복 없이 서로 달라야 함 (예: 'Pepperoni,Pepperoni,Onion' ❌)토핑 이름은 알파벳 순서대로 나열해야 함 (예: 'Chicken,Onions,Sausage' ✅)..

SQL 2025.04.28

Histogram of Users and Purchases: Walmart SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/histogram-users-purchases Walmart SQL Interview Question | DataLemurWalmart SQL Interview Question: Write a query to retrieve the the users along with the number of products they bought.datalemur.com🧢 Walmart 사용자 거래 내역 문제 요약목적: 사용자별 가장 최근 거래일 기준으로 거래일, user_id, 구매한 상품 개수를 조회하기조건: 가장 최근 거래일만 대상으로 집계, 결과는 거래일 기준 오름차순으로 정렬1. 내 풀이먼저 날짜별(user_id, transaction..

SQL 2025.04.28

User Shopping Sprees: Amazon SQL Interview Question

문제풀이 링크: https://datalemur.com/questions/amazon-shopping-spree👒 아마존 쇼핑 스프리 고객 식별 문제 요약목적: 쇼핑 스프리를 경험한 고객(user_id)을 식별조건: 3일 이상 연속으로 구매한 이력이 있어야 하며, 최종 출력은 user_id 기준 오름차순 정렬쇼핑 스프리 정의:3일 이상 연속해서 매일 구매한 경우를 쇼핑 스프리로 인정 셀프 조인(Self Join) 사용:같은 테이블을 2번 조인하여 거래 날짜가 +1일, +2일 차이 나는 레코드 연결이때, user_id가 같은 경우만 조인DATE() 함수로 날짜만 비교:transaction_date에 시간이 포함되기 때문에 DATE()로 시간을 제거하고 날짜만 뽑아 정확한 하루 단위 비교 SELECT T1..

SQL 2025.04.28

Advertiser Status: Facebook SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/updated-status 🧾 페이스북 광고주 결제 상태 업데이트 문제 요약목적: 광고주(user_id)의 결제 상태(payment status)를 daily_pay 정보를 바탕으로 업데이트조건: 최종 출력은 user_id와 갱신된 상태를 포함하며, user_id 기준으로 정렬상태 분류:NEW: 신규 광고주, 첫 결제 완료EXISTING: 이전에도 결제했었고, 이번에도 결제한 광고주CHURN: 이전에 결제했었지만, 이번엔 결제 안 한 광고주RESURRECT: 과거에 결제 이력이 끊겼다가 이번에 결제한 광고주규칙 정리:결제 안 했으면:이전 상태가 있으면 → CHURN이전 상태가 없고 결제도 안 한 경우는 존재할 수 없음→ dail..

SQL 2025.04.26

Maximize Prime Item Inventory: Amazon SQL Interview Question

문제 풀이 링크: https://datalemur.com/questions/prime-warehouse-storage Amazon SQL Interview Question | DataLemurAmazon SQL Interview Question: Write a query to maximise the prime and non-prime items in a warehouse.datalemur.com🏬 아마존 창고 최적화 문제 요약목적: 500,000 제곱피트의 창고 공간을 최대한 효율적으로 사용조건: 프라임 상품 배치(prime_eligible)를 가능한 많이 넣고, 남은 공간에 논프라임 배치(not_prime) 추가각 배치는 여러 상품으로 구성된 세트 단위이며, 분리해서 넣을 수 없음 (prime_eli..

SQL 2025.04.25