테이블 join 질문드립니다.
본문
<table>
<thead>
<tr>
<th>순위</th>
<th>총판장</th>
<th>구매품목</th>
<th>판매품목</th>
<th>총 구매금액</th>
<th>총 판매금액</th>
</tr>
</thead>
<tbody>
<?
$sum_count = "0";
$sql = "
select a.mb_id
, count(*) as cnt, group_concat(a.wr_12 separator '||') wr_12a, group_concat(b.wr_12 separator '||') wr_12b, sum(a.wr_31) as tota, sum(b.wr_31) as totb
, (select c.mb_name from g5_member c where a.mb_id = c.mb_id) mb_name
from g5_write_csorder a
inner join g5_write_cscenter b on a.mb_id = b.mb_id
where
a.wr_29 between '{$stx1}' and '{$stx2}' and a.wr_50 like '%{$stx7}%' and NOT a.wr_54 IN ('exchange') and
b.wr_29 between '{$stx1}' and '{$stx2}' and b.wr_50 like '%{$stx7}%'
group by a.mb_id ORDER BY tota DESC
";
$result = sql_query($sql, TRUE);
while ($row = sql_fetch_array($result)) {
$list_namea = explode('||',$row['wr_12a']);
$numa = array_count_values($list_namea);
$list_nameb = explode('||',$row['wr_12b']);
$numb = array_count_values($list_nameb);
$sum_count ++
?>
<tr>
<td class="td_c"><?php echo $sum_count ?>위</td>
<td class="td_c"><?php echo $row['mb_name'] ?></td>
<td class="td">
<?php foreach( $numa as $key => $value ){ ?>
<?php echo $key; ?>(<?php echo $value?>),
<?php } ?>
</td>
<td class="td">
<?php foreach( $numb as $key => $value ){ ?>
<?php echo $key; ?>(<?php echo $value?>),
<?php } ?>
</td>
<td class="td_r"><?php echo number_format(str_replace(',', '', $row['tota']) / 2) ?>원</td>
<td class="td_r"><?php echo number_format(str_replace(',', '', $row['totb']) / 2) ?>원</td>
<?php } ?>
</table>
g5_write_csorder(구매)의 제품명과 개수, 금액은 제대로 가져오는데
g5_write_cscenter(판매) 의 제품개수와 금액(totb)이 맞질 않네요... 품목은 맞는데...
어떻게 해야 제대로 된 값이 나올까요?
!-->
답변을 작성하시기 전에 로그인 해주세요.