ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [1주차] SQL 1주차
    카테고리 없음 2022. 12. 20. 13:13

    스파르타코딩클럽 내일배움단 '엑셀보다 쉬운 SQL'

    1주차 주요 내용: select, where 그리고 같이 쓰는 문법

     

    프로그램: dbeaver - MYSQL 사용

     

    [시작]

    select * from orders
    where payment_method = 'kakaopay';

    orders 라는 테이블로부터 *(전체)를 선택

    어디서? payment_method 필드가 'kakaopay'인 것만!

    - 문자는 반드시 ' ' 처리

    - 각 줄마다 ctrl+enter로 실행하면서 확인하면 좋음

    - 에러는 반드시 읽어보고 확인하기

     

    [where절과 자주 같이쓰는 문법]

    - 같지 않음 (!=)

    select * from orders
    where payment_method != 'CARD';

    - 범위 (between and )

    select * from orders
    where created_at between "2020-07-13" and "2020-07-15";

    : 13일~14일 사이면 between "2020-07-13" and "2020-07-15" 라고 써야 함

    - 포함 (in)

    select * from checkins
    where week in (1,3);

    - 패턴 (like)

    select * from users
    where email like '%gmail.com'

    - 일부 데이터만 가져오기 (limit) : 방대한 데이터를 확인할 때

    select * from orders
    where patment_method = 'kakaopay'
    limit 5;

    - 숫자 세기 (count)

    select count(*) from users

    - 중복데이터 제외 (distinct)

    select distinct(payment_method) from orders;

    - 함수 여러개 쓰기 (distinct와 count)

    select count(distinct(payment_method)) from orders;

     

Designed by Tistory.