[2024.07.22 TIL] sql 조건문

박지영·2024년 7월 22일
0

Today I Learned

목록 보기
15/67

IF, CASE 조건문

  • 조건에 따라 다른 방법을 적용하고 싶을 때 IF
    ex)if( 조건식, true, false) 별칭
    select restaurant_name,
            cuisine_type "원래 음식 타입",
            if(cuisine_type='Korean', '한식', '기타') "음식 타입"
     from food_orders
  • 조건을 여러가지 지정하고 싶을 떄 CASE
    ex)case when 조건1 then 값(수식)1
             when 조건2 then 값(수식)2
             else 값(수식)3
        end
    select order_id,
            price,
            quantity,
            case when quantity=1 then price
                 when quantity>=2 then price/quantity end "음식 단가"
     from food_orders
profile
신입 개발자

0개의 댓글