본문 바로가기

MYSQL/solvesql17

세션 유지 시간을 10분으로 재정의하기 https://solvesql.com/problems/redefine-session-2/ 정답 쿼리WITH event_party AS (SELECT user_pseudo_id, ga_session_id, event_timestamp_kst, LAG(event_timestamp_kst) OVER(ORDER BY event_timestamp_kst) AS prev_event, CASE WHEN LAG(event_timestamp_kst) OVER(ORDER BY event_timestamp_kst) IS NULL OR (julianday(event_timestamp_kst) - julianday(LAG(event_times.. 2025. 7. 14.
스테디셀러 작가 찾기 https://solvesql.com/problems/find-steadyseller-writers/ https://solvesql.com/problems/find-steadyseller-writers/ solvesql.comWITH TEMP AS( SELECT DISTINCT author, year, DENSE_RANK() OVER (PARTITION BY author ORDER BY year) AS NUM FROM books WHERE Genre = 'Fiction'), TEMP2 AS( SELECT *, year - NUM AS straight FROM TEMP)SELECT .. 2025. 7. 11.
세션 재정의하기 https://solvesql.com/problems/redefine-session/ https://solvesql.com/problems/redefine-session/ solvesql.com WITH session_split AS( SELECT user_pseudo_id, event_timestamp_kst, LAG(event_timestamp_kst) OVER (ORDER BY event_timestamp_kst) AS prev_event, CASE WHEN LAG(event_timestamp_kst) OVER (ORDER BY event_timestamp_kst) IS NULL OR (juliand.. 2025. 7. 10.
카테고리 별 매출 비율 https://solvesql.com/problems/revenue-pct-per-category/ https://solvesql.com/problems/revenue-pct-per-category/ solvesql.com LV.5 인데 LV.4 보다 쉬운 것 같다.WITH TEMP AS( SELECT DISTINCT category, sub_category, ROUND(SUM(sales) OVER(PARTITION BY sub_category), 2) AS sales_sub_category, ROUND(SUM(sales) OVER(PARTITION BY category), 2) AS sales_category, ROUND(SUM(sales) OVER(),.. 2025. 7. 10.
폐쇄할 따릉이 정류소 찾기 1 https://solvesql.com/problems/find-unnecessary-station-1/ https://solvesql.com/problems/find-unnecessary-station-1/ solvesql.com SELECT S.station_id, S.nameFROM station S LEFT JOIN station near_s ON S.station_id != near_s.station_idWHERE S.updated_at = 5 주목할 점공식 보다 중요한건 JOIN 부분 같다. JOIN에서 조건이 불일치하는 공식은 처음 써보는데 앞으로 유용할 것 같다. 2025. 7. 7.
펭귄 날개와 몸무게의 상관 계수 Palmer Penguins 데이터베이스는 펭귄의 서식지, 종, 부리 길이 등 펭귄 연구 데이터를 담고 있습니다.펭귄은 일반적으로 날개 길이가 길 수록 큰 펭귄이기 때문에 몸무게도 늘어납니다. 따라서 날개 길이와 몸무게 사이에는 양의 상관 관계가 있습니다. 다만, 펭귄 종에 따라 상관 관계의 정도가 다릅니다. 이를 확인하기 위해 날개 길이와 몸무게의 피어슨 상관 계수(Pearson Correlation Coefficient)를 구하는 쿼리를 작성해주세요.쿼리 결과에는 아래 컬럼이 포함되어 있어야 하고, 상관 계수는 소수점 아래 넷째 자리에서 반올림 해 셋째 자리까지 출력되어야 합니다.SELECT species, ROUND (SUM((flipper_length_mm - avg_flipper) * .. 2025. 7. 2.