SQL Training #26 - 33 함수들

· 6년 전 · 1423

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;

https://www.youtube.com/watch?v=b0lOdcVI4CE&list=PLD20298E653A970F8&index=26

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;

https://www.youtube.com/watch?v=obKnx6IY5X4&list=PLD20298E653A970F8&index=27

SQL Convert Function

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

https://www.youtube.com/watch?v=fqwD7h3kkMw&list=PLD20298E653A970F8&index=28

SQL Concatenate

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

https://www.youtube.com/watch?v=CA9RFedFXlg&list=PLD20298E653A970F8&index=29

SQL Substring

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

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

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

https://www.youtube.com/watch?v=3U96oI37MgE&list=PLD20298E653A970F8&index=30

SQL CharIndex - Instring

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

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

https://www.youtube.com/watch?v=lStyUa2vRHE&list=PLD20298E653A970F8&index=31

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          ');

 

https://www.youtube.com/watch?v=yzj3Jey-syM&list=PLD20298E653A970F8&index=32

SQL Length

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

len대신에 LENGTH

https://www.youtube.com/watch?v=e-qPy7CAH4Y&list=PLD20298E653A970F8&index=33

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

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,347
6년 전 조회 1,168
6년 전 조회 1,759
6년 전 조회 1,232
6년 전 조회 1,393
6년 전 조회 1,448
6년 전 조회 1,272
6년 전 조회 1,484
6년 전 조회 1,232
6년 전 조회 1,199
6년 전 조회 1,340
6년 전 조회 1,307
6년 전 조회 3,231
6년 전 조회 1,421
6년 전 조회 1,424
6년 전 조회 1,443
6년 전 조회 1,041
6년 전 조회 816
6년 전 조회 933
6년 전 조회 1,032
6년 전 조회 1,298
6년 전 조회 847
6년 전 조회 713
6년 전 조회 956
6년 전 조회 768
6년 전 조회 547
6년 전 조회 685
6년 전 조회 635
6년 전 조회 638
6년 전 조회 580