inblog logo
|
parangdajavous
    Data Base

    [Data Base] 2. SELECT Basic

    김미숙's avatar
    김미숙
    Feb 26, 2025
    [Data Base] 2. SELECT Basic
    Contents
    1. 용어 정리2. Select 문법 기본

    1. 용어 정리

    • select (프로젝션 도구)
    • from (하드디스크의 테이블을 메모리로 퍼올리는 것)
    • where (행 고르기 - 하드디스크에서 연산됨)
    • projection (특정한 열만 선택하는 것)
    • table (전체 껍데기)
    • column (칼럼 제목)
    • row = record (행)
    • cursor (→)
    • fullscan (전체 데이터를 다 봄)
    • constraint (칼럼에 제약을 줌)
    • unique (유일하다)
    • index → random access / 다이렉트한 접근 가능. 유일하면 index가 유리
    • schema (DB내에 어떤 구조로 데이터가 저장되는가를 나타내는 데이터베이스 구조)
    notion image
     
    schema
    schema
     
     

    2. Select 문법 기본

    select

    select* from emp;
    notion image
     

    상세 보기

    ‼️
    varchar의 ( )숫자는 최대 저장할 수 있는 문자 수를 의미
    varchar(20) → 20자의 문자열 저장 가능
    varchar(9) → 9자의 문자열 저장 가능
    desc emp;
    notion image
     

    별칭 주기

    ‼️
    별칭을 영어로 적을 경우 소문자로 적고 띄어쓰기는 _ 로 함
    select empno as '사원번호' from emp;
    notion image
    -- as 생략가능함 select ename '이름' from emp;
    notion image
     

    중복 제거

    --distinct_서로 다른 집합을 만든다 select distinct job from emp;
    notion image
     

    연결 연산자

    select concat(ename,'의 직업은 ',job) "직원소개" from emp;
    notion image
     
    select ename "이름", concat(sal*12 + ifnull(comm, 0), "$") "연봉" from emp;
    notion image
     

    연산자

    select ename, sal*12 from emp;
    notion image
     

    원하는 행 찾기

    select * from emp where ename = 'SMITH';
    notion image
     
    select * from emp where hiredate = '1980-12-17';
    notion image
     
    select * from emp where hiredate = '1980/12/17';
    notion image
     
    select * from emp where sal > 2000;
    notion image
     
    select * from emp where comm is null;
    notion image
     
    select * from emp where comm is not null;
    notion image
     
     

    where

    select * from emp where sal = 800 and deptno = 20;
    notion image
     
    select * from emp where sal = 800 or sal = 1600;
    notion image
     
    select * from emp where sal in (800,1600);
    notion image
     
    select * from emp where sal between 800 and 3000;
    notion image
     

    Like 연산자

    select * from emp where ename like 'S%';
    notion image
     
    select * from emp where ename like'%M%';
    notion image
     
    select * from emp where ename like'_M%';
    notion image
     
    select * from emp where ename like '___T%';
    notion image
     

    정규 표현식(Regular Expression)

    -- 어떤 문자열에서 특수한 규칙을 찾아야할 때 select * from professor where name regexp '조|형'; -- or 를 표현하며 x 또는 y 문자가 존재함을 의미
    notion image
     
    SELECT * FROM professor WHERE email REGEXP '^[^@]+@[^@]+\.net$';
    notion image
     
    SELECT 'Password1!' REGEXP '^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{8,}$' AS is_valid from dual; -- 생략가능
    notion image
     
    SELECT 'Password!' REGEXP '^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{8,}$' AS is_valid from dual; -- 생략가능
    notion image
    Share article
    Contents
    1. 용어 정리2. Select 문법 기본

    parangdajavous

    RSS·Powered by Inblog