전체 글

남들의 귀감이 될때까지!!
·SQL/MySQL
기본구조 CREATE FUNCTION 'function name' ('parameter name', 'datatype') RETURNS 'datatype' (DETERMINSTIC) BEGIN DECLARE 'varialbe name' 'datatype'; SET ; RETURN (Query) / 'variable name'; END 사용방법 SELECT 'function name' (parameter) 예제 문제 Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | ..
·SQL/MySQL
문제 Table: Employee +--------------+---------+ | Column Name | Type | +--------------+---------+ | id | int | | name | varchar | | salary | int | | departmentId | int | +--------------+---------+ id is the primary key column for this table. departmentId is a foreign key of the ID from the Department table. Each row of this table indicates the ID, name, and salary of an employee. It also contains ..
·SQL/MySQL
문제 Table: Logs +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id is the primary key for this table. Write an SQL query to find all numbers that appear at least three times consecutively. Return the result table in any order. The query result format is in the following example. Example 1: Input: Logs table: +----..
·SQL/MySQL
기본 틀 함수(컬럼) OVER (PARTITION BY 컬럼 ORDER BY 컬럼) PARTITION BY는 기존에 배운 GROUP BY랑 비슷한 원리라 생각하면 편하다. 집계 함수 (AVG,MIN,MAX,COUNT,SUM 등) MAX(컬럼) OVER (PARTITION BY 컬럼) Employee table id Name Salary DepartmentId MaxSalary 1 Joe 70000 1 90000 2 Jim 90000 1 90000 3 Henry 80000 2 80000 4 Sam 60000 2 80000 5 Max 90000 1 90000 예시 코드 SELECT id, Name, Salary, DepartmentId, Max(Salary) OVER (PARTITION BY Departme..
카펫 문제 설명 Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 갈색으로 색칠된 격자의 개수는 기억했지만, 전체 카펫의 크기는 기억하지 못했습니다. Leo가 본 카펫에서 갈색 격자의 수 brown, 노란색 격자의 수 yellow가 매개변수로 주어질 때 카펫의 가로, 세로 크기를 순서대로 배열에 담아 return 하도록 solution 함수를 작성해주세요. 제한사항 갈색 격자의 수 brown은 8 이상 5,000 이하인 자연수입니다. 노란색 격자의 수 yellow는 1 이상 2,000,000 이하인 자연수입니다. 카펫의 가로 길이는 세로 길이와 같거나, 세로 길이..
·SQL/MySQL
문제설명 Table: Logs +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id is the primary key for this table. Write an SQL query to find all numbers that appear at least three times consecutively. Return the result table in any order. The query result format is in the following example. Example 1: Input: Logs table: +--..
·SQL/MySQL
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 first. ..
큰 수 만들기 문제 설명 어떤 숫자에서 k개의 수를 제거했을 때 얻을 수 있는 가장 큰 숫자를 구하려 합니다. 예를 들어, 숫자 1924에서 수 두 개를 제거하면 [19, 12, 14, 92, 94, 24] 를 만들 수 있습니다. 이 중 가장 큰 숫자는 94 입니다. 문자열 형식으로 숫자 number와 제거할 수의 개수 k가 solution 함수의 매개변수로 주어집니다. number에서 k 개의 수를 제거했을 때 만들 수 있는 수 중 가장 큰 숫자를 문자열 형태로 return 하도록 solution 함수를 완성하세요. 제한 조건 number는 1자리 이상, 1,000,000자리 이하인 숫자입니다. k는 1 이상 number의 자릿수 미만인 자연수입니다. 입출력 예 number k return "1924"..
·SQL/MySQL
with 문 MySQL에서는 WITH문으로 가상 테이블을 만들 수 있는데 작성방법은 다음과 같다. WITH 가상테이블 명 AS ( SELECT ~~ FROM ~~~ 등등 )이러한 방법은 전 글의 https://sunho99.tistory.com/entry/MySQL-Subquery%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%9C-%EC%8B%AC%ED%99%94%EB%AC%B8%EC%A0%9C-Hacker-Rank-Challenges%ED%92%80%EC%96%B4%EB%B3%B4%EA%B8%B0 에 해당하는 문제를 풀때도 사용 할 수 있다. WITH counter AS( SELECT hackers.hacker_id, hackers.name, COUNT(*) AS challenges_c..
Shine_sunho
How to study for us