고요빛물결

SQL Training #26 - 33 함수들

· 2019-06-23 (일) 02:08:46 · 1565

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튜닝

64건
+
제목 글쓴이 날짜 조회
21-05-30 조회 1,422
21-05-30 조회 1,313
21-05-22 조회 1,649
21-05-21 조회 1,326
21-05-15 조회 1,063
21-05-15 조회 1,148
21-03-28 조회 969
21-03-24 조회 1,580
19-09-20 조회 1,891
19-09-19 조회 1,990
19-07-26 조회 1,865
19-07-25 조회 1,424
19-07-24 조회 1,127
19-07-23 조회 1,409
19-07-23 조회 1,459
19-07-23 조회 1,288
19-07-22 조회 1,903
19-07-18 조회 1,336
19-07-17 조회 1,503
19-07-16 조회 1,580
19-07-16 조회 1,413
19-07-15 조회 1,628
19-07-03 조회 1,365
19-06-27 조회 1,353
19-06-26 조회 1,479
19-06-25 조회 1,469
19-06-25 조회 3,384
19-06-24 조회 1,559
19-06-23 조회 1,566
19-06-23 조회 1,604