목록분류 전체보기 (103)
working_helen
HackerRank 코딩테스트 연습 Medium & HardOccupations : pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output should consist of four columns (Doctor, Professor, Singer, and Actor) in that specific order, with their respective names listed alphabetically under each column. 풀이 1 > PIVOT 함수SELECT *FROM 테이블명PIVO..
HackerRank 코딩테스트 연습 Easy & Medium Weather Observation Station 5 : Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically. 풀이 1- 정렬만을 가지고 쉽게 record를 얻기 위해 LENGTH(CITY) 오름차순 정렬했을 때, 내림차순 정렬했..
Leetcode 코딩테스트 연습 MySQL Hard✅ 계층형 질의 1) 계층형 데이터 - 동일한 table 내 행끼리 상위/하위 관계가 있는 경우 - 하나의 table에서 특정 행이 다른 행의 상위(부모) 또는 하위(자식) 역할을 하는 데이터 구조- 계층형 데이터는 트리 구조로 설명 가능root node : 최상위 부모 행leaf node : 자식이 없는 최하위 행depth : root node 로부터 특정 노드까지의 거리, root부터 1이며 leaf로 내려갈 때마다 1씩 증가 2) 계층형 질의 Hierarchical Query - 계층형 데이터를 탐색하기 위한 SQL문 - 계층형 데이터를 특정 시작 지점부터 상위/하위 관계를 따라 depth를 탐색하며 쿼리 수행 SELECT 칼럼명FROM 테이블명S..
Leetcode 코딩테스트 연습 MySQL Med. ~ Hard3564. Seasonal Sales Analysis : Find the most popular product category for each season. The popularity of a category is determined by the total quantity sold in that season. If there is a tie, select the category with the highest total revenue (quantity × price). 풀이 : WITH 구문 사용- WITH로 여러 임시 쿼리를 생성할 땐 ' , '로 연결- 앞서 생성한 CTE를 뒤에 생성한 CTE에서 호출 가능 반대는 불가능하므로 CTE 의존..
Leetcode 코딩테스트 연습 MySQL Med.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. 풀이 : ROWNUM- where절에서 rownum을 사용하기 위해 서브쿼리로 묶기- 절대적인 행 번호가 아닌 가상의 번호이므로 '(..
Leetcode 코딩테스트 연습 MySQL Med.1158. Market Analysis I: Write a solution to find for each user, the join date and the number of orders they made as a buyer in 2019. > 존재하지 않는 경우도 결과에 포함하여 출력하는 문제 풀이- 포함되어야 하는 모든 value를 가지고 있는 Users table을 기준으로 outer join- ON절에 AND를 바로 연결해서 JOIN 과정에서 불필요한 record 제거 select u.user_id as buyer_id, to_char(u.join_date, 'YYYY-MM-DD') as join_date, count(o.order_date) as..
Leetcode 코딩테스트 연습 MySQL Med.1934. Confirmation Rate : The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. > 존재하지 않는 경우도 결과에 포함하여 출력하는 문제 풀이 1- 서브 쿼리로 원하는 정보를 가진 table 생성한 후 포함되어야 하는 모든 value를 가지고 있는 table과 outer joinselect user..
Leetcode 코딩테스트 연습 MySQL Med.3497. Analyze Subscription Conversion: A subscription service wants to analyze user behavior patterns. The company offers a 7-day free trial, after which users can subscribe to a paid plan or cancel. Find users who converted from free trial to paid subscription. Calculate each user's average daily activity duration during their free trial period. Calculate each user's..
SQL 구문 연습과 함께 데이터베이스와 관련된 개념적인 부분에 대해 공부해본다. 1. Database 2. Phase of DB design 3. Entity-Relationship Model (ER model)4. Relational Model5. SQL 1. Database1) 등장 배경 - Big Data와 Web Scale Computing의 등장으로 대용량 데이터를 효율적으로 관리해야할 필요성이 강화 - 초기 데이터 저장 방식은 File System, 많은 문제점이 존재redundancy : 같은 데이터가 여러 파일에 중복 저장 integrity : integrity가 보장되지 않아 무결성 문제에 취약consistency : atomic update가 불가능concurrent access..
Leetcode 코딩테스트 연습 MySQL Easy1633. Percentage of Users Attended a Contest: find the percentage of the users registered in each contest rounded to two decimals 풀이 1- select 문 내에서 서브쿼리 사용select contest_id, round(count(contest_id)/(select count(*) from Users)*100, 2) as percentagefrom Register group by contest_idorder by 2 desc, 1 풀이 2 > count가 0인 조합까지 포함해서 모든 가능한 조합별 개수 세기- cross join으로 모든 가능한 조합이 ..