'DataBase' 카테고리의 글 목록
뇌 채우기 공간
DataBase/MySQL
[MySQL] 데이터 제어어 DCL: 권한부여, 권한 삭제 grant, revoke
2020.11.25
1) 사용자 추가하기 1 create user 'abc'@'localhost' identified by '1234'; cs id: abc password : 1234 2) 사용자 삭제하기 1 2 drop user 'abc'@'localhost'; cs 3) 권한 부여하기 1 2 3 4 5 -- 모든 권한 부여하기 -- all privieges 는 모든 권한을 *.*은 모든 데이터베이스의 모든 테이블을 뜻한다. grant all privileges on *.* to 'abc'@'localhost'; grant all privileges on sqldb.* to 'abc'@'localhost'; grant all privileges on sqldb.usertbl to 'abc'@'localhost'; cs ..

DataBase/MySQL
[MySQL] 집계함수와 group by, having절 , rollup
2020.11.25
기본적 쿼리 문의 순서이다. select from WHERE group by having order by 1. 1) 집계함수, group by - 합계 sum userid별로 구매한 건수를 userid오름차순으로 출력하라ㅇ 1 2 3 4 5 -- sum() 집계함수, 집계함수가 나오면 무조건 group by가 나와야한다. select userid, sum(amount) from buytbl group by userid -- userid별로 나타내겠다는 말 order by userid; -- userid 별로 asc로 출력하겠다는 말(오름차순) cs 2)평균 avg 사용자 아이디 별 평균 구매 건수를 내림 차순으로 출력하라 1 2 3 4 5 select userid as '사용자 아이디' , avg(amo..

DataBase/MySQL
[MySQL] ORDER BY / 정렬/ 내림차순 정렬/ 오름차순 정렬
2020.11.24
1) 오름차순 정렬 asc 1 2 3 select * from usertbl order by mdate asc; cs mdate기준으로 오름차순 정렬한다는 뜻입니다. asc는 생략해도 됩니다. mdate는 날짜 데이터이므로 오름차순으로 정렬하면 예전부터 현재에 가까워지는 순으로 정렬됩니다. 2) 내림차순 desc 1 2 3 select * from usertbl order by mdate desc; cs 내림차순은 desc이고 생략 불가능합니다. 위와 반대의 결과가 나옵니다. 3) 여러개 컬럼 정렬 1 2 3 4 select * from usertbl order by height desc,name asc; cs height는 desc, name은 asc로 정렬하라는 뜻입니다. heigh..

DataBase/MySQL
[MySQL] 서브쿼리/ any, some , all / 둘 중 하나만 만족, 둘 다 만족
2020.11.24
1. 서브쿼리 1 2 3 4 5 select name, height from usertbl where height> (select height from usertbl where name = '김경호'); cs height가 조건인데 그 조건이 쿼리문이다. 서브 쿼리문을 보면 usertbl테이블에서 name이 김경호인 height를 얻어서 괄호를 대체한다고 생각하면 된다. 김경호의 height가 177이라고 저장되어있다면 전체적으로 usertbl에서 height가 177 초과인 name, height컬럼을 얻고 싶은 것이다. (usertbl에서 김경호보다 키가 큰 데이터의 name, height를 뽑아내고 있음) 1 2 3 4 5 select name, height from usertbl where hei..
DataBase/MySQL
[MySQL] select , where절 조건 / in, between, and , or, like, is null
2020.11.24
1. SELECT 테이블에서 데이터를 조회 1 2 3 select * from buytbl; cs buytbl 테이블의 모든 데이터 조회 2. WHERE SELECT 컬럼명 FROM 테이블명 WHERE 조건; 1) 조건이 문자열인 경우 1 2 3 select * from usertbl where name = '김경호'; cs 2) 조건이 상수인 경우 1 2 3 select * from usertbl where birthyear= 1987; cs 3) 조건 두개를 모두 만족하는 데이터를 출력할 때 and 1 2 3 4 select userid, name -- userid, namd을 가져온다. from usertbl -- 이 테이블에서 where birthyear >= 1970 -- 조건 where and..