sfjlsjfl
106
2017-12-07 18:39:07.0 작성 2017-12-07 18:44:37.0 수정됨
2
128

2가지 쿼리 차이점좀 알려주세요~ |


1.

select  AA.* ,BB.name as cash_item_name , CC.name as pay_item_name
 from tb_cash AA 
 left join tb_item BB on AA.cash_item_idx=BB.idx  
 left join tb_item CC on AA.pay_item_idx=CC.idx   
where AA.tb_seller_idx="1004"  and AA.cash_dt="2017-12-06"  and AA.tb_user_idx="10001" and AA.cash_cd ="입금" order by AA.idx desc

2.

select AA.* ,IFNULL(BB.in_price,0) as in_price , IFNULL(CC.out_price,0) as out_price from  tb_user_cash AA 
left outer join
(
select cash_dt,tb_user_idx ,sum(price) as  in_price  from tb_cash
where cash_dt='2017-12-07'
and cash_cd='입금'
and pay_item_idx=2
group by cash_dt,tb_user_idx
) AS BB on AA.cash_dt=BB.cash_dt and AA.tb_user_idx=BB.tb_user_idx

left outer join
(
select cash_dt,tb_user_idx ,sum(price) as  out_price  from tb_cash
where cash_dt='2017-12-07'
and cash_cd='지급'
and pay_item_idx=2
group by cash_dt,tb_user_idx
)AS CC on(AA.cash_dt=CC.cash_dt and AA.tb_user_idx=CC.tb_user_idx)


1번은 FROM 밑에 LEFT JOIN이 2개가 있고

2번은 LEFT OUTER JOIN 이후 SELECT가 들어가고 또 LEFT OUTER JOIN이후에 SELECT가 또들어가고 궁금합니다

0
0
  • 답변 2

  • 스타
    2k
    2017-12-07 19:22:01.0

    용도가 달라서 차이가 나는거고,

    문법은 그냥 문서 보는 게 좋을 것 같은데요..

    0
  • siva6
    3k
    2017-12-07 19:53:48.0

    2번은 inline-view라고 보통 불러요.

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.