MySQL) 데이터 정렬 및 집계 조회 하기(+order by, count, avg, sum, max/min, group by, having절)
#1. order by 컬럼명 … asc/desc 데이터를 조회하면서 특정 칼럼을 기준으로 값을 정렬할 때 쓴다. 내림차순은 desc 오름차순은 asc #2. 집계함수: count, avg, sum, max, min **집계함수를 쓸 때는 집계함수 외의 나머지 칼럼은 꼭 Group by 뒤에 와야 하고, 그 칼럼들에 대해서 조건을 걸 때는 having을 쓴다 (where는 못씀) **각 명령어 순서를 지켜야 함 (안 쓰는 명령어는 생략 가능) select from where group by having order by
2021. 4. 27.
MySQL) 데이터 다양한 옵션으로 조회하기 (+left/right, substring, replace, concat, trim, instr, upper, lower)
#1. left(컬럼명, 길이) #2. right(컬럼명, 길이) #3. substring(컬럼명, 문자열시작위치, 개수) #4. replace(컬럼명, '바꿀내용','바꿔진내용') #5. concat(컬럼명이나 추가할 내용 값을 쉼표로 나열) #6. trim(컬럼명), rtrim, ltrim -->공백 없애기 #7. char_length(컬럼명) --> 문자열 음절수 세기 #8. instr(컬럼명, '인덱스찾을내용') --> 특정 글자가 시작하는 인덱스 찾기 #9. upper(컬럼명), lower(컬럼명) --> 대문자, 소문자로 만들기 #10. limit(행시작하는 위치 숫자, 불러올 행 숫자)
2021. 4. 27.
MySQL) 테이블 생성/버리기/변경, 기본키 설정 (+create, drop, alter, primary key, auto_increment...)
#1. 테이블 생성: create table `table name` ( ``칼럼명` 글자속성 null/not null., … primary key (`컬럼명`) ) engine=innodb, default charset=`utf8` comment='…'; #2. 테이블 생성시 참조키 설정하기: create table `table name` ( ``칼럼명` 글자속성 null/not null., … primary key (`컬럼명`), foreign key (``참조컬럼명`) references ``대상테이블명` (``대상테이블 컬럼명`) ) engine=innodb, default charset=`utf8` comment='…'; #3. 테이블 버리기: drop table `테이블명`; #4. 테이블 구조..
2021. 4. 27.