이전 목록 다음
채택완료

sql문 질문 2

2020-03-19 (목) 11:24:03 2,708
Copy
SELECT 
so.site_id AS site_id, 
ac.c_name AS company_name,
SUM(so.od_cart_price) AS buying_sum 
FROM 
company ac LEFT outer join g5_shop_order so on ac.site_id= so.site_id 
LEFT outer join g5_shop_cart cart on so.od_id=cart.od_id 
LEFT outer join g5_shop_item item on cart.it_id=item.it_id
WHERE so.site_id ='aaa' 
AND cart.ct_status = '완료' 
AND ( item.ca_id LIKE '00%' OR item.ca_id2 LIKE '00%' OR item.ca_id3 LIKE '00%' ) 
AND so.od_test = '0' 
GROUP BY so.site_id order by buying_sum desc

이런 sql문이 있습니다

site_id ='aaa'라는 조건문을 줘서 매출 합계를 내고 싶은데요.

문제가

만약에 옵션이 추가된 주문의 경우에 buying_sum이 이상합니다 ㅠ

예를들면 ) 옵션추가 상품은 해당 제품가격이 또+ 됩니다 ㅠㅠ

어떻게 하면 정상적으로 나올까요?ㅠ

조인을 뭔가 잘못한거같은데..왜그런지 모르겟어요 ㅠ

|

답변 2개

채택된 답변
+20 포인트

https://limkydev.tistory.com/144

참조하셔서..

inner join 으로 변경하셔야 할듯 하네요..^^

sum 할게 잘못됐었네요...ㅎ

답변을 작성하려면 로그인이 필요합니다.