커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
abs 활용 (4주차 4회 실습)
엑셀보다 쉽고 빠른 SQL v0
4주차
북마크
김*원
댓글
4
추천
0
조회수
13
조회수
13
답변 완료

4주차 4회 실습 2번을 좀 더 해보고 있는데,

할인 금액까지 구하고, 실제 소비자 가격을 더 한번 구하려고 total_sales-discount_ratio 뺄셈 연산을 했는데,

에러가 나서 구글링 해보니 abs 사용하라고 되어 있어서 아래처럼 썼더니 에러가 뜨더라구요.ㅠ

왜 그런걸까요? abs는 무조건 from이 별도로(?) 있어야 하는건지..!


참고로 이후에 뭔가 그룹을 해줘야할까 싶어서 b 그룹을 만들고,

아래와 정상으로 나오는건 확인했는데, 이유가 궁금합니다!





#비정상 출력코드

select restaurant_name, total_quantity, total_sales,

abs(total_sales-discount_ratio) 'final_price',

case when total_quantity<=5 then total_sales*0.1

when total_quantity>15 and total_sales>=300000 then total_sales*0.005

else total_sales*0.01 end discount_ratio

from

(

select restaurant_name, sum(quantity) total_quantity, sum(price) total_sales

from food_orders fo

group by restaurant_name

) a


스파르타 즉문즉답




------------------------------------------------------

#정상출력 코드 (b그룹 추가생성 후 abs 활용)

select restaurant_name, total_quantity, total_sales, discount_ratio,

abs(total_sales-discount_ratio) as customer_price

from

(

select restaurant_name, total_quantity, total_sales,

case when total_quantity<=5 then total_sales*0.1

when total_quantity>15 and total_sales>=300000 then total_sales*0.005

else total_sales*0.01 end discount_ratio

from

(

select restaurant_name, sum(quantity) total_quantity, sum(price) total_sales

from food_orders fo

group by restaurant_name

) a

) b


스파르타 즉문즉답


취소
 공유
취소
댓글 0
댓글 알림
나의얼굴