SQL Training #26 - 33 함수들

· 6년 전 · 1494

SQL Round Function

select * from simpledb.employee;

select avg(salary) from simpledb.employee;

select round(avg(salary), 2) from simpledb.employee;

마이너스로도 사용이 가능합니다.   당연히 반올림되죠

select round(avg(salary), -2) from simpledb.employee;

SQL Cast Function

Type이 BINARY, CHAR, DATE, DATETIME, TIME,DECIMAL, SIGNED, UNSIGNED

만 지원되네요. ( http://www.mysqltutorial.org/mysql-cast/ )

select cast(salary as signed ) from simpledb.employee;

select cast(salary as char(50) ) from simpledb.employee;

+ 대신에 concat를 사용하기 때문에 자동으로 숫자는 String으로 변경.

select concat(employee_name, salary) from simpledb.employee;

SQL Convert Function

Mysql 에서는 Cast()와 Convert() 같은것 같습니다.

SQL Concatenate

https://www.w3schools.com/sql/func_mysql_concat.asp

SQL Substring

https://www.w3schools.com/sql/func_mysql_substring.asp

시작은 1부터 0을 하면 첫글자 앞이네요

select substring(employee_name, 1, 3) from simpledb.employee;

SQL CharIndex - Instring

MySQL에서는 locate를 사용합니다. https://www.w3schools.com/sql/func_mysql_locate.asp

select locate('R', employee_name) from simpledb.employee;

SQL Trim, Rtrim, Ltrim

https://www.w3schools.com/sql/func_mysql_trim.asp

https://www.w3schools.com/sql/func_mysql_rtrim.asp

https://www.w3schools.com/sql/func_mysql_ltrim.asp

 

select '      hello       ';

select trim('      hello          ');

 

SQL Length

https://www.w3schools.com/sql/func_mysql_length.asp

len대신에 LENGTH

|
댓글을 작성하시려면 로그인이 필요합니다.

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,397
6년 전 조회 1,232
6년 전 조회 1,821
6년 전 조회 1,279
6년 전 조회 1,450
6년 전 조회 1,514
6년 전 조회 1,341
6년 전 조회 1,556
6년 전 조회 1,302
6년 전 조회 1,279
6년 전 조회 1,406
6년 전 조회 1,372
6년 전 조회 3,303
6년 전 조회 1,486
6년 전 조회 1,495
6년 전 조회 1,527
6년 전 조회 1,102
6년 전 조회 876
6년 전 조회 977
6년 전 조회 1,078
6년 전 조회 1,356
6년 전 조회 931
6년 전 조회 779
6년 전 조회 1,014
6년 전 조회 827
6년 전 조회 597
6년 전 조회 747
6년 전 조회 686
6년 전 조회 692
6년 전 조회 638