SQL Query

심야·2022년 12월 6일
0

웹 개발

목록 보기
47/47
  • show tables;
    table 출력

  • desc employees;
    테이블 구조

  • select * from employees limit 0, 10;
    10개씩 조회

  • select first_name, last_name, salary from employees;
    first_name, last_name, salary 컬럼만 조회

  • select first_name as 이름, hire_date as 입사일 from employees;
    alias

  • select concat(first_name, ' ', last_name) as 이름, hire_date as 입사일 from employees;
    first_name, last_name을 공백 기준으로 합친다.

  • select distinct manager_id from employees;
    중복 제거

  • select first_name, last_name, hire_date, salary from employees order by salary desc;
    오름차순 정렬

  • select * from employees where last_name = "king";
    last name이 'king'인 사람을 조회

  • select * from employees where hire_date > '1998-02-05' order by hire_date;
    hire_date > 1998-02-05인 사람만 조회하고 정렬

  • select * from employees where first_name = 'steven' and last_name = 'king';
    first_name과 last_name이 일치하는 사람을 조회

  • select * from employees where first_name = 'steven' or last_name = 'king';

  • select * from employees where commission_pct is null;
    commission_pct 컬럼 값이 null인 경우만 조회

  • select * from employees where first_name like '%t';
    패턴 매칭

  • select * from employees where first_name like 'H____';
    패턴 매칭

  • select * from employees where department_id = 90 or department_id = 100;

  • select * from employees where department_id in(90, 100);
    위 쿼리와 똑같은 결과를 조회

  • select ucase(last_name) from employees;
    대문자로 변경해 조회

  • select upper(last_name) from employees;

  • select lcase(last_name) from employees;
    소문자로 변경해 조회

  • select substring('happy day', 4,2);
    4인덱스부터 문자열 2개 조회

  • select substring(first_name, 1, 1) from employees;

  • select * from employees where substring(first_name, 1, 1) = 'A';

  • select * from employees where first_name like 'A%';
    substring 보다 like 사용을 추천한다.

profile
하루하루 성실하게, 인생 전체는 되는대로.

0개의 댓글