테스트 사이트 - 개발 중인 베타 버전입니다

쿼리문 질문드립니다. 채택완료

밀랍 3년 전 조회 1,319

</p>

<p><?php

$write_table = $g5['write_prefix'] . $bo_table;

$sum_count = "0";

$sql = "

    select a.mb_id, b.mb_name, group_concat(wr_32 separator '||') wr_32, count(*) as cnt , sum(a.wr_23) as tot

      from {$write_table} a

               left outer join {$g5['member_table']} b on a.mb_id = b.mb_id

     where wr_29 between '{$stx1}' and '{$stx2}' and wr_50 like '%{$stx10}%'

     group by a.mb_id, b.mb_name ORDER BY tot DESC

";

$result = sql_query($sql, true);

while ($row = sql_fetch_array($result)) {

    $counts_cash = array_sum(explode('||',str_replace(',', '', $row['wr_32'])));

    $tmp= sql_fetch( "select count(*) cnt from {$g5['member_table']} where mb_9='{$row['mb_id']}'") ;

    $sum_count ++;

?>

<tr>

    <td class="td_c"><?php echo $sum_count; ?>위</td>

    <td class="td_c"><?php echo $tmp['cnt']; ?> 명</td>

    <td class="td_c"><?php echo $row['cnt']; ?> 번</td>

    <td class="td_r"><?php echo number_format($counts_cash); ?>원</td>

<?php } ?></p>

<p>

 

wr_32가 배열로 되어 있는 금액입니다.

배열값을 합해서 counts_cash로 뿌려주고 있습니다.

 

본인을 (mb_9 ,후원인) 후견인으로 두고 있는 회원 인원수는 $tmp로 뽑아서 몇명인지 까지는 나오는데

이 후원인의 wr_32값을 가져와서 뿌려줄려면 어떻게 해야 하나요?

 

즉 본인의 wr_32의 합한 금액과 본인아이디를 후원인으로 둔 회원들의 wr_32값을 합한 금액을 뽑고 싶습니다. ( $tmp[cnt]가 10명이면 그 10명의 wr_32를 합한 값)

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

답변 1개

채택된 답변
+20 포인트
 from {$write_table} a
               left outer join {$g5['member_table']} b on a.mb_id = b.mb_id
     where wr_29 

==

b.wr_29 조건을 where에서 사용하신다면

left 조인 대신 inner join을 사용하세요.

로그인 후 평가할 수 있습니다

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

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

로그인