본문 바로가기

Study/SQL

(17)
MySQL | Temporary Table Temporary Table 이란? MySQL 단일 세션에서 여러번 사용할 수 있는 데이터 집합을 임시적으로 저장해둔 테이블을 칭한다. 일례로, 대용량의 데이터가 저장된 테이블에서 특정 값들만 추출하여 간결하게 보려고 할 때, 해당 테이블 전체를 활용하게 되면 성능이나 비용 부분에서 부담이 생길 경우가 생길 수 있다. 이 때 Temporary Table을 이용하여 간결하게 데이터를 활용할 수 있다. Temporary Table 특징 테이블 생성시 CREATE TEMPORARY TABLE \테이블명\ 의 구조를 가진다. Temporary Table의 경우 해당 테이블을 생성한 클라이언트 단에서만 확인이 가능하다 서로 다른 클라이언트와 이름이 중복되어도 오류없이 생성 가능하나, 동일한 세션에서 이름이 중복될..
MySQL | HackerRank | Ollivander's Inventory Question Harry Potter and his friends are at Ollivander's with Ron, finally replacing Charlie's old broken wand. Hermione decides the best way to choose is by determining the minimum number of gold galleons needed to buy each non-evil wand of high power and age. Write a query to print the id, age, coins_needed, and power of the wands that Ron's interested in, sorted in order of descending power...
MySQL | HackerRank | Top Earners Question We define an employee's total earnings to be their monthly Salary * Months worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as 2 space-separated integers. Input ..
MySQL | HackerRank | Top Competitors Question Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same ..
MySQL | HackerRank | The Report Problem You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks. Grades contains the following data: Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered..
MySQL | HackerRank | The PADS Problem Generate the following two result sets: Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S). Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences i..
MySQL | HackerRank | Weather Observation Station 20 Problem A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to decimal places. Input Format The STATION table is described as follows: where LAT_N is the northern latitude and LONG_W is the western longitude. Solve Oracle 의 경우, 중위값을 구할 때 median() 함수로 쉽게 해당 값을 구할 수 있다. M..
MySQL | HackerRank | New Companies Problem Amber's conglomerate corporation just acquired some new companies. Each of the companies follows this hierarchy: Given the table schemas below, write a query to print the company_code, founder name, total number of lead managers, total number of senior managers, total number of managers, and total number of employees. Order your output by ascending company_code. Note: The tables may cont..