쿼리문 질문드립니다. 채택완료
밀랍
3년 전
조회 3,647
</p>
<p> select a.mb_name, b.mb_id, c.mb_id, count(*) as cnt,
count(DISTINCT b.wr_31) as b_number,
count(DISTINCT c.wr_31) as c_number,
sum(DISTINCT b.wr_31) as totb,
sum(DISTINCT c.wr_31) as totc,
from g5_member a
inner join {$write_table} b on a.mb_id = b.mb_id
inner join {$write_target} c on b.mb_id = c.mb_id
where
b.wr_29 between '{$stx1}' and '{$stx2}' and b.wr_41 like '%{$stx3}%' and
c.wr_29 between '{$stx1}' and '{$stx2}' and c.wr_41 like '%{$stx3}%'
group by a.mb_name</p>
<p>
B게시판과 C게시판을 비교해서 값을 내는 쿼리문인데요...
뽑아내고 보니까 B게시판과 C게시판에 모두 글을 작성 한 회훤만 뽑아내고 있습니다.
둘중 하나라도 작성한 회원도 뽑아낼려면 어떻게 해야 하나요?
한곳에만 적은 회원은 다른 게시판에 0원으로 처리해서 뽑아내면 되는데.. 그게 잘 안되고 있습니다.
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
채택된 답변
+20 포인트
답변에 대한 댓글 3개
�
밀랍
3년 전
outer join 하니까 에러가 떠버리네요 ㅠㅠ
�
폭주죽
3년 전
from g5_member a
inner join {$write_table} b on a.mb_id = b.mb_id
inner join {$write_target} c on b.mb_id = c.mb_id
where
b.wr_29 between '{$stx1}' and '{$stx2}' and b.wr_41 like '%{$stx3}%' and
c.wr_29 between '{$stx1}' and '{$stx2}' and c.wr_41 like '%{$stx3}%'
를
[code]
from
g5_member a
inner join
{$write_table} b
on
a.mb_id = b.mb_id
left outer join
{$write_target} c
on
b.mb_id = c.mb_id
and c.wr_29 between '{$stx1}' and '{$stx2}'
and c.wr_41 like '%{$stx3}%'
where
b.wr_29 between '{$stx1}' and '{$stx2}'
and b.wr_41 like '%{$stx3}%'
[/code]
이렇게 수정해보시면 어떨지 ㅎㅎ
inner join {$write_table} b on a.mb_id = b.mb_id
inner join {$write_target} c on b.mb_id = c.mb_id
where
b.wr_29 between '{$stx1}' and '{$stx2}' and b.wr_41 like '%{$stx3}%' and
c.wr_29 between '{$stx1}' and '{$stx2}' and c.wr_41 like '%{$stx3}%'
를
[code]
from
g5_member a
inner join
{$write_table} b
on
a.mb_id = b.mb_id
left outer join
{$write_target} c
on
b.mb_id = c.mb_id
and c.wr_29 between '{$stx1}' and '{$stx2}'
and c.wr_41 like '%{$stx3}%'
where
b.wr_29 between '{$stx1}' and '{$stx2}'
and b.wr_41 like '%{$stx3}%'
[/code]
이렇게 수정해보시면 어떨지 ㅎㅎ
�
밀랍
3년 전
감사합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인