-- 원하는 별명(alias) as로 데이터 가져오기 select stu_no as ID, sub_no as SD, enr_grade as 성적 from pgi.enrol;
- 컬럼 별칭 정의
-- 두 개 이상의 열을 합쳐서 검색 select concat(stu_dept,' ',stu_name, '입니다') as 학과성명 from student;
- concat
-- 학과가 컴퓨터정보 이외의 학과만 출력 select distinct stu_dept from student where stu_dept <> '컴퓨터정보학부';
- <>연산자 대신 !=도 가능
- SELECT * FROM student WHERE NOT stu_dept = '컴퓨터정보학부';
- 조건 전체를 부정하고 싶을 때 NOT을 앞에 붙일 수 있음.- SELECT * FROM student WHERE stu_dept NOT IN ('컴퓨터정보학부', '기계공학부', '전자과');
- 제외해야 할 학과가 많다면 <>를 여러 번 쓰는 것보다 NOT IN이 훨씬 효율적
-- 원하는 개수 만큼 데이터 가져오기 select * from stduent limit 5; --인덱스 1부터 5 select * from student limit 1, 5;
- limit - 반환되는 행의 수 제한
select * from student where stu_weight between 60 and 70;
- 범위 조건(between A and b)
- A <= stu_weight <= B
is null - null인 값
is not null - null이 아닌 값
select stu_no, stu_name from student order by stu_no desc; ```
- ORDER BY 절은 가장 마지막에서 정렬 순서를 지정 - ASC 오름차순, DESC 내림차순
select stu_no, stu_name, stu_weight-5 as target from student order by target, stu_name;
- target이 먼저 정렬되고 그 이후에 stu_name이 정렬
select stu_no, stu_name, stu_weight-5 as target from student order 3;
- 열의 3번째 컬럼에 있는속성으로 정렬