DataBase/Mysql

[SQL] Select 쿼리문, Where절 연습하기

민돌v 2022. 1. 5. 17:59
728x90

Select문과 같이쓰는 문법들 정리!

 

1) 같지  않음 (!=)

select * from orders
where course_title != "영어";

 

2) 범위 조건 (between)

select * from orders
where data '07-13' between '08-12'

 

3) 포함 조건 (in)

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

    - 1,3 주차 주문

 

4)  패턴(문자열 규칙) 조건 (Like)

select * from users 
where email like '%daum.net';

🍯Like의 다양한 사용법

  • where email like 'a%': email 필드값이 a로 시작하는 모든 데이터
  • where email like '%a' email 필드값이 a로 끝나는 모든 데이터
  • where email like '%co%' email 필드값에 co를 포함하는 모든 데이터
  • where email like 'a%o' email 필드값이 a로 시작하고 o로 끝나는 모든 데이터

 

5) 일부 데이터(개수)만 가져오기 (Limit)

select * from orders 
where payment_method = "kakaopay"
limit 5;

 

6) 중복 데이터 제거 (Distinct)

select distinct(payment_method) from orders;

 

7) Count

select count(*) from orders

 

 

끄트읕 하나씩 하나씩 레츠고

반응형