5월 28일 실습 (round, dataetime, str관련 함수)
함수의 활용
● dateime, strftime
● round(반올림),min, max
● count, sum, avg
● length, trim, ltrim, rtrim, instr , substr
- 문자열 관련 trim = 문자열 짜르는것. left, right, 문자열 내부 검색, 문자열 내부 특정한 부분 추출
round(반올림할 수, 소수점 자리수) - 반올림하는 함수.
strftime 함수
이달의 마지막 날
select strftime('start of monthy', '+1 month', '-1 days');
=>select strftime('%Y-%m-%d','now', 'start of month','+1 months', '-1 days');
본 과정을 시작한 후 경과 일
- select strftime('%d ', 'now', '-10 days' );
=> select strftime('%j ', 'now') - strftime('%j', '2018-05-10');
올해 마지막 날(2018-12-31)의 요일
=> select strftime('%Y-%m-%d', 'now', 'start of year', '+1 year', '-1 day');
min, max
최소값 , 최대값
트랙 테이블에는 각 트랙의 파일 크기( Byte)가 기록되어 있다.
트랙중 파일 크기가 가장 큰 것과, 가장 작은것의 트랙 이름을 구하라.
select min(Bytes) from tracks;
select max(Bytes) from tracks;
count, sum, avg
count = 세다
sum = 합
avg = 평균
미국에 살고 있는 고객의 명수
-select count(country) from customers where country = 'USA';
Bluse장르의 트랙 갯수
- select count(TrackID) from tracks where TrackID==6;
invoice_items 테이블에 기록된 주문량(Quantity)의 합계
-select sum(quantity) from invoice_items;
트랙 파일의 평균 크기를 소수점 3자리 표시되고 반올림 처림
- select round(avg(Bytes),3) from tracks;
2번째 문제는 잘못됨. 아래 그림의 genreid로 하여야 한다.
문자열 - 왼쪽부터 하나의 알파벳 씩 인데스 값을 가짐.(맨 왼쪽부터 1부터 시작)
length :문자열 길이를 반환
trim('문자','삭제 할 문자') :문자열의 왼쪽/오른쪽 끝의 문자를 삭제
trim은 원래 공백 제거용이였으나, 문자삭제도 활용 가능하다.
ex) select trim ('abcdefga', 'a'); 라고 입력시 => bcdefg 를 출력 양쪽 a를 지운다.
instr('문자','검색할 문자') :문자열 내 특정 문자열을 검색
- 문자의 위치를 알려준다.
substr('문자',문자위치, 위치로부터 출력할 자리수.) :문자열을 특정 위치, 특정 길이로 절단
/abcdef/
trim은 원래 공백 제거용이였으나, 문자삭제도 활용 가능하다.
sql의 문자열 인덱스는 1부터 시작한다.
a b c d e f
1 2 3 4 5
trim은 원래 공백 제거용이였으나, 문자삭제도 활용 가능하다.
rtrim은 right trim으로 문자열에 오른쪽을 지운다. 없으면 지우지 않는다.
ltrim은 left trim으로 왼쪽 문자열을 지운다.
academy로 시작하는 아티스트 이름의 목록을 출력하면서 academy of 문자를 제외하고 출력
=> select ltrim(name, 'Academy of') from artists where name like 'academy%';
직원의 타이틀 중 세번째 문자부터 다섯번 째 문자까지 출력한 목록.
=> select substr(title ,3, 5) from employees;
직원의 타이틀 중 문자열 이 시작되는 문자열 인덱스의 목록
=> select instr(title, 'Ssru') from employees;
symphony로 끝나는 아티스트 이름의 목록을 symphony 문자를 제외하고 출력함.
- select name rtrim('symphony','symphony') from artists where name like '%symphony';
=> select rtrim(name,'symphony') from artists where name like '%symphony';
트랙의 이름의 길이가 10미만의 목록
=> select name, length(name) from tracks where length(name) < 10;
virsual Box -환경설정-네트워크에서 nat 네트워크 추가
사설 IP설정
그리고 FreeBSD설치(설치는 생략함)후에 가상시스템 내보내기
파일- 가상 시스템 가져오기를 클릭. 확장자명이 .ova파일을(아래그림에서는 freeBSD.ova) 불러온다.
vitual machine내에서 모든 네트워크의 MAC 주소 초기화