함수
1.NULL 처리
SELECT IFNULL(Column명, "NULL일 경우 대체 값") as 별칭 from 테이블 명
https://school.programmers.co.kr/learn/courses/30/lessons/59410
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
2.DATETIME 형 변환
SELECT date_format(Column명,"원하는 date_format") as 별칭 from 테이블 명
date_format 목록
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format
MySQL :: MySQL 5.7 Reference Manual :: 12.7 Date and Time Functions
12.7 Date and Time Functions This section describes the functions that can be used to manipulate temporal values. See Section 11.2, “Date and Time Data Types”, for a description of the range of values each date and time type has and the valid formats
dev.mysql.com
https://school.programmers.co.kr/learn/courses/30/lessons/59414
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
3.IF 문
SELECT IF(조건,조건만족시 값 ,조건 불만족시 값) as 별칭 from 테이블명
https://school.programmers.co.kr/learn/courses/30/lessons/59409
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
4.case 문
select
case
when 조건1 then 조건1 만족시 값
when 조건2 then 조건2 만족시 값 ...
else 모든 조건 불만족시 값
end as 별칭
from 테이블 명
https://school.programmers.co.kr/learn/courses/30/lessons/131113
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
5.left,right,mid,substring
left(문자,가져올 갯수)
right(문자,가져올 갯수)
mid(문자,시작위치,가져올 갯수) = substring(문자,시작위치,가져올 갯수)
select * from 테이블명 where left(column명, "가져올 갯수") = "조건"
https://school.programmers.co.kr/learn/courses/30/lessons/131114
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
6.round(),truncate()
round(숫자,반올림할 자릿수):반올림할 자릿수 +1에서 반올림
truncate(숫자,버릴 자릿수):버릴 자릿수 밑에 값 버림,버릴 자릿수 필수 표시
ex)
round(3123.156,1) = 3123.2
round(3123.156,0) = 3123
round(3123.156,-1) = 3120
truncate(3123.156,1) = 3123.1
truncate(3123.156,-1) = 3123
https://school.programmers.co.kr/learn/courses/30/lessons/131534
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
7.rank(),dense_rank()
ex)
rank() over (order by cnt desc) : cnt column을 내림차순을 기준으로 rank
dense_rank() over (order by cnt desc): cnt column을 내림차순을 기준으로 dense_rank
https://school.programmers.co.kr/learn/courses/30/lessons/131124
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
8.datediff(),timestampdiff()
ex)
datediff(날짜1,날짜2) : 날짜1과 날짜2의 일 수 차이 출력
timestampdiff(단위,날짜1,날짜2)
단위
second : 초
minute : 분
hour : 시
day : 일
week : 주
month : 월
quarter : 분기
year : 연
https://school.programmers.co.kr/learn/courses/30/lessons/151138
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
9.concat()
ex)
concat(str1,str2): str1 str2 문자열 합치기
concat("1","+","2") : 1+2
https://school.programmers.co.kr/learn/courses/30/lessons/164671
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr