Study_note(zb_data)/SQL

스터디 노트 (Scalar Functions)

KloudHyun 2023. 8. 30. 20:42

📌 Scalar Functions

출처 : 제로베이스 데이터 스쿨

📌 UCASE

- 영문을 대문자로 변환

select ucase('This is ucase test.');

select ucase(menu) from sandwich where price>15;

📌 LCASE

- 소문자로 반환

select lcase("THIS IS LCASE TEST.");
select lcase(menu) from sandwich where price < 5

📌 MID

select MID(string, start_position, length);
# string - 원본 문자열
# start - 문자열 반환 시작 위치 (첫글자는 1, 마지막 글자는 -1)
# length - 반환할 문자열 길이 (공백 포함)
select mid('This is mid test.', 1, 6);

📌 LENGTH

- 문장의 길이를 반환하는 함수

select length('This is len test.');

select length(address), address from sandwich where ranking <= 3;

📌 ROUND

- 소수점 반올림

- 일 단위 위치는 -1

select round(315.625, 1)

select round(315.625, -1)

select ranking, price, round(price) from sandwich
order by ranking desc limit 3;

📌 NOW

- 현재 날짜 및 시간을 반환하는 함수

SELECT NOW();

📌 FORMAT

- 숫자를 천 단위로 콤마를 적용해주는 함수

select format(12345.6789, 0)

select 상호, 주소, format(가격, 0) from oil_price where round(가격, -3) >= 2000 group by 상호