본문 바로가기
728x90

TIL - 프로그래밍292

[SQL] 소수점 올림, 반올림, 내림, 자르기 CEILING(값) 값을 그보다 큰 가장 가까운 정수로 올림 FLOOR(값) 값을 그보다 작은 가장 가까운 정수로 내림 SELECT CEILING(3.14159); # 4 SELECT FLOOR(3.14159); # 3 ROUND(값, n) 값이 소수점 n자릿수가 되도록 반올림 TRUNCATE(값, n) 값이 소수점 n자릿수가 되도록 버림 SELECT ROUND(3.14159, 2); # 3.14 SELECT TRUNCATE(3.14159, 2); # 3.14 2023. 7. 8.
[SQL] 정규표현식 - 해커랭크 Weather Observation Station 6~11 정규표현식 튜토리얼: https://regexone.com/lesson/introduction_abcs RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, and the ABCs Regular expressions are extremely useful in extracting information from text such as code, log files, spreadsheets, or even documents. And while there is a lot of theory behind formal languages, the following lessons and examples will explore the more prac rege.. 2023. 7. 7.
[리트코드] 180. Consecutive Numbers - MySQL https://leetcode.com/problems/consecutive-numbers/ Consecutive Numbers - LeetCode Can you solve this real interview question? Consecutive Numbers - Table: Logs +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id is the primary key for this table. id is an leetcode.com 문제 연속하는 3개의 num이 같은 num 출력하라 풀이 1 - JOIN 연속하는 .. 2023. 7. 6.
[해커랭크] The Report - MySQL https://www.hackerrank.com/challenges/the-report/problem The Report | HackerRank Write a query to generate a report containing three columns: Name, Grade and Mark. www.hackerrank.com 문제 8점보다 낮은 점수 학생의 이름은 원하지 않는다. Grade 내림차순으로 (학생이름, Grade, Marks) 출력 조건 8~10점 분포의 학생은 이름순으로 정렬 1~7점 분포의 학생은 Marks으로 정렬 + 이름은 NULL로 지정 풀이 Grades 테이블을 통해 각 학생의 Grade 구하기 SELECT * FROM Students AS s INNER JOIN Grades AS.. 2023. 7. 6.
[SQL] WITH 절 / WITH RECURSIVE 절 WITH 절 임시테이블 or 가상 테이블 반복되는 서브쿼리 블록을 하나의 WITH 절 블록으로 만들어서 사용 가능 한 번 실행할 쿼리문 내 정의하여 해당 쿼리 안에서만 실행 # 가상 테이블 만들기 WITH 이를 지칭할 테이블명(new) AS ( 서브쿼리 ) # 사용 SELECT new.id FROM new; WITH RECURSIVE 절 가상 테이블을 생성하면서 가상 테이블 자신의 값을 참조하여 값을 결정할 때 사용 -- 0~23 시간 컬럼 만들기 WITH RECURSIVE TIME_HOUR AS ( SELECT 0 AS H UNION SELECT H+1 FROM TIME_HOUR WHERE H < 23 ) 2023. 7. 6.
[해커랭크] Challenges - MySQL https://www.hackerrank.com/challenges/challenges/problem Challenges | HackerRank Print the total number of challenges created by hackers. www.hackerrank.com 문제 해커id, 이름, 각 학생이 만든 챌린지 수(challenges_created) 출력 challenges_created 내림차순, 해커id 오름차순 정렬 challenges_created가 같은 사람이 존재할 때 challenges_created가 최댓값이라면 출력 challenges_created가 최댓값이 아니라면 제외 풀이 CODE1 : 요구사항 1번, 2번 -- 출력 해커id, 이름, 각 학생이 만든 챌린지 수(ch.. 2023. 7. 6.
반응형