전체 글

Another Hound Cafe
# 문제https://leetcode.com/problems/group-sold-products-by-the-date/description/  # 문제 설명  # 핵심 개념 그룹별로 컬럼의 값을 , 로 합쳐주는 함수group_concat( 합칠값 )  # 정답 코드select date_format(sell_date, '%Y-%m-%d') as sell_date, count(distinct product) as num_sold, group_concat(distinct product) as productsfrom Activitiesgroup by sell_date
# 문제https://leetcode.com/problems/delete-duplicate-emails/description/ # 문제 설명 email값 같으면서 id값이 다른경우 큰 id값 삭제하기  # 핵심 개념 delete from 테이블where 조건 이용하기  # 정답 코드delete pfrom Person p, Person qwhere p.id > q.id and p.email = q.email
# 문제https://leetcode.com/problems/patients-with-a-condition/description/ # 문제 요약 DIAB1을 포함하는 것을 찾기1) DIAB1로 시작하거나2) 중간에 있을경우 공백포함  # 새롭게 알게된 사실 SELECT SUBSTRING_INDEX('사과,바나나,딸기,포도', ',', 3); 3번째 , 전까지 출력하기   SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('사과,바나나,딸기,포도', ',', 3), ',', -1) 3번째 전까지 출력한 '사과, 바나나, 딸기' 에서마지막 -1것인 딸기 출력   SELECT SUBSTRING_INDEX('사과,바나나,딸기,포도', ',', -3); -3부터 -2, -1이런식으로 간다   ..
# 문제https://leetcode.com/problems/fix-names-in-a-table/description/  # 문제 요약앞글자만 대문자로 바꾸기나머지는 소문자로 바꾸기  # 문제 핵심 substring(컬럼, 시작위치, 개수)SELECT substring('으하하하하하하와하하하하', 1, 3)   upper()대문자로 만든다 lower()소문자로 만든다 concat()문자열 연결  # 정답 코드select user_id, concat(upper(substring(name, 1, 1)), lower(substring(name, 2))) as name from Usersorder by user_id
# 문제 https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/description/  # 문제 요약가장 친구가 많은 사람의 번호와 그 숫자를 세기  # 문제 핵심 테이블을 합치는 방식1. 조인2. union 이번 문제에서는 union all을 사용하여 합쳤다  # 정답 코드with cte as ( select requester_id as id from RequestAccepted union all select accepter_id as id from RequestAccepted), cte2 as ( select id, count(*) as num from cte group..
# 데이터 분석 주제 아마존 식품 데이터 분석을 진행하였다  # 사용한 컬럼들  # 사용 데이터  # 계산된 필드 만들기 총매출 -> sum([Sales Margin Amount])총수익 -> sum([Sales Amount])거래수 -> countd([order id])고객수 -> countd([custkey)  # 데이터 형식 top_pairs.csv의 word(상품) 컬럼과df_category_2.csv의 word(상품) 컬럼을 조인하였다!    word별 invoice Number의 카운트값 = 상품별 구매개수   # 열과 행 열 : Invoice Number (카운트)행 : Word  # 마크 색상입히기Word  # 필터   1. Category컨텍스트 추가일반 - 모두사용상위 - 없음  Q) ..
1. 데이터 로드하기 여러 패키지 가져오기import pandas as pdimport sklearnimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsimport osimport re  데이터 csv파일로 읽어오기df = pd.read_csv('df_category_2.csv')df.head(3)   ⚡️아이템별 마진합계, 평균수량 구하기word_stats = df.groupby('word').agg({ 'Sales Margin Amount' : 'sum', 'Sales Quantity' : 'mean'}).rename(columns = {'Sales Quantity' : 'Avg Quantity'}) word_stat..
# 프로젝트 주제 : 아마존 고객 구매 식품 데이터 분석   # 컬럼 설명 ✔️Discount Amount : 할인금액✔️List Amount : 정가 / 할인전금액✔️Sales Amount : 실제판매금액-> Sales Price * Sales Quantity ✔️Sales Amount Based on List Price : 할인적용 안된 판매금액 전체 ✔️Sales Cost Amount : 상품을 판매하는데 들어간 비용 ✔️Sales Margin Amount : 판매 마진 금액-> Sales Amount - Sales Cost Amount ✔️Sales Price : 실제 판매 가격✔️Sales Quantity : 상품 수량   1. 데이터 로드하기 여러 패키지 가져오기import pandas as ..
# 문제https://leetcode.com/problems/restaurant-growth/description/ # 문제 요약 7일 이상부터 7일동안의 amount합계와 평균값 구하기 (소수점2자리)  # 핵심 개념 1. 먼저 group by visited_on으로 같은 날짜의 amount값을 합쳐주었다-> 가상테이블 cte1생성 2. 집계함수 over ( order by / rows between 6 preceding and current row) as 별칭으로7일동안의 합과 갯수를 세어주었다-> 가상테이블 cte2 생성sum(amount) over (order by visited_onrows between 6 preceding and current row) as amount,count(*) ove..
# 문제https://leetcode.com/problems/movie-rating/  # 문제 설명  1. 영화후기를 가장 많이 남긴 유저를 찾고, 동점시 이름빠른 순서대로 1명 가져오기 2. 2월중에서 영화 평점이 높은 영화를 찾고, 동점시 이름빠른 순서대로 1개 가져오기  # 핵심개념 1. 마지막 union all시 가상테이블 with에서 만든 테이블에서 컬럼만 가져와서 합쳐주기 2. 2월중을 조건으로 쓸때 created_at >= '2020-02-01' and created_at    # 정답 코드 with cte as ( select r.user_id, name, r.movie_id, title, rating, created_at from MovieRating r inner j..
파카파오
Another Hound