QCC | 3회차 코드 리뷰 & 피드백
·
SQL
☑️  문제1:  첫 주문 고객 연도별 매출 조회 [문제] “2011년 12월”에 첫 주문을 한 고객들의 연도별 매출을 조회하는 SQL 문을 작성하세요. 고객 이름은 이름과 성을 결합하여 생성합니다. 결과는 고객 ID(customerid)기준 오름차순, 연도(year) 기준 오름차순으로 정렬합니다.[문제 풀이]내 코드 SELECT so.customerid ,concat(c.firstname," ",c.lastname) AS customer_name ,year(so.orderdate) AS 'year' ,round(sum(so.orderqty*so.unitprice),2) AS gmvFROM sales_order so INNER JOIN customer c ON so.customerid = c..
코테 준비 | Friend Requests II: Who Has the Most Friends / Investments in 2016 (union all / 중복값만 or 중복값이 아닌 행만 필터링 하기)
·
SQL
☑️  602. Friend Requests II: Who Has the Most Friends[문제]Write a solution to find the people who have the most friends and the most friends number.The test cases are generated so that only one person has the most friends.가장 많은 친구를 가진 사람과 그 수 조회하기[문제 풀이]내 코드 WITH total AS ( SELECT requester_id as id ,count(distinct accepter_id) as n FROM REQUESTACCEPTED GROUP BY requester_id UNIO..
코테 준비 | Restaurant Growth(이동 평균, 누적 합 구하기 - 윈도우함수/연관 서브쿼리/ N 행 이후부터 끝까지 출력하기)
·
SQL
☑️  1321. Restaurant Growth[문제]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.The result format is in tReturn the result table ordered by visited_on in ascending order.레스토랑 테이블에서 일주일(6일전-현재) 까지 누적합 및 이동평균 구하기 (+7일 이후부터 출력)[문제 풀이]내 코드 - 윈도우 함수WITH daily_sales AS (-- 일별 매출집계..
코테 준비 | Movie Rating (JOIN,UNION ALL)
·
SQL
☑️  1341. Movie Rating[문제]Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.두 가지 조건에 해당하는 출력값 각각 집계후 합쳐주기 ( UNION 사용) [문제 풀이]내 코드 (SELECT u.name AS results-- 각각에서 찾아주고, 출력값 연결해..
코테 준비 | Exchange Seats ( 홀수 짝수 자리바꾸기 - LAG,LEAD)
·
SQL
☑️  626. Exchange Seats[문제]Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.Return the result table ordered by id in ascending order.아이디 짝수에서 홀수로 자리 바꾸기[문제 풀이]내 코드 WITH oby AS ( # 홀수 짝수 카운팅SELECT id,student ,ROW_NUMBER() OVER (PARTITION BY id%2=1 ORDER BY id) AS rownFROM SEAT), idx AS(SELECT s..
코테연습 | Last Person to Fit in the Bus & Count Salary Categories (UNION 없는 행 추가/ 누적합 SUM() OVER)
·
SQL
☑️  1204. Last Person to Fit in the Bus[문제] There is a queue of people waiting to board a bus. However, the bus has a weight limit of 1000 kilograms, so there may be some people who cannot board.Write a solution to find the person_name of the last person that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight ..
코테 준비 | Percentage of Users Attended a Contest / Queries Quality and Percentage
·
SQL
☑️ Queries Quality and Percentage[문제]We define query quality as: The average of the ratio between query rating and its position. We also define poor query percentage as: The percentage of all queries with rating less than 3.Both quality and poor_query_percentage should be rounded to 2 decimal places.[문제 풀이]정답 코드SELECT QUERY_NAME ,ROUND(AVG(RATING/POSITION),2) AS QUALITY ,ROUND(COUNT(IF(R..
QCC | 2회차 코드 리뷰 & 피드백
·
SQL
🔑 문제를 제대로 잘 읽을 것 !🔑 날짜 조건은 디테일을 잘 확인 할 것 ☑️ 문제1.  이메일 프로모션에 동의한 고객 수 구하기[문제 조건]- Person_Person 테이블을 사용하여 다음 조건을 만족하는 고객의 수를 구하세요- 이메일 프로모션에 “동의”한 고객 해당 고객들 중 "개인(소매)" 고객의 수- 출력 컬럼 : customer_counts→ WHERE 절로 필터링 하기 [문제 해결]테이블 확인emailpromotion 컬럼에 고유 값 확인 :  0 (프로모션 x) 1,2 (프로모션 o)emailpromotion  컬럼에 null 값 여부 확인 : 없음 `왜?` 0이 아닌경우로 필터링 할경우 null값도 출력 되기 때문에 같이 확인함 조건 emailpromotion 컬럼에서 프로모션에 동의..
QCC | 1회차 코드 리뷰 & 피드백
·
SQL
☑️문제1. 전년도 국민총생산(GNP)이 없거나 전년 대비 GNP가 감소한 국가 중 인구가 1천만 명 이상인 국가의 수 조회하기 [문제 조건]-  전년도 국민 총 생산값이 없거나  전년대비 cnp가 감소한 국가 중-  인구가 1천만명 이상인 국가 갯수 집계-  출력 컬럼 : 국가의 수  [문제 해결]테이블 확인  ( 조건별 필터링만 하면 됨)전년도 gnp : gnpold 컬럼올해 gnp : gnp 컬럼에 값 저장인구 수 : population 조건 파악 및 작성전년도 국민 총 생산량이 없거나 전년대비 gnp 감소 : `WHERE (GNP GNPOld OR GNPOld IS NULL)`인구가 1천만명 이상인 국가 : `Population>10000000`where절에서 필터링 시, gnp 내용은 `or` ..
Dbeaver | 디비버 네비게이터 패널 보이게 하기 / 디비버 쿼리 실행 속도 (성능) 확인법
·
SQL
☑️ 디비버에서 네비게이터 패널 사라졌을때 해결법window →rest perspective  → rest perspective 좌측 네비게이터 패널이 생긴다! ☑️ 디비버에서 쿼리별 실행 속도 (성능) 확인법 window →show view→ query manager풀이 방식 별 쿼리의 성능을 쿼리 매니저 `duration` 지표로 비교 확인 할 수있다.