sql 질문입니다..(카운트세기)
본문
<?
$query = "SELECT * FROM g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";
$sql = sql_query($query);
$state_1 = sql_fetch(" select count(*) as cnt from {$g5['board_new_table']} where addarea='작업지시' ");
?>
<style type="text/css">
*{
padding:0;
margin:0;
}
table, tr, td{ border: 1px solid #ddd;
}
</style>
<table class="table table-bordered">
<tr>
<th >아이디</th>
<th >작업지시</th>
<th >승인대기</th>
<th >승인완료</th>
<th >승인거절</th>
<th >작업완료</th>
<th >기간만료</th>
</tr>
<?php while($row= sql_fetch_array($sql)) { ?>
<tr>
<td><?php echo $row["dateco_id"]; ?></td>
<td> <?php echo $state_1['cnt']?></td>
</tr> <?php } ?>
</table>
질문은 이러합니다.
g5_board_new에 있는 아이디를 뿌리고, 그 아이디와 연결된 단어들의 숫자를 같이 뿌리고 싶습니다.
예)
아이디 |
작업지시 |
승인대기 |
승인완료 |
홍길동 |
10 |
0 |
5 |
장길산 |
10 |
1 |
4 |
임꺽정 |
5 |
20 |
9 |
이런식으로 해당아이디와 연결되는 단어의 숫자를 세고 싶습니다.
위 코드를 작성하면 g5_board_new에 있는 아이디는 정상적으로 뿌려집니다.
근데 그 아이디에 연결되는 단어의 숫자를 어떻게 뿌려야할지 감이 안잡혀서요,,,
혹시 도움을 구할 수 잇을까요?
아님 불가능한가요?
답변 4
이런건 제작의뢰에 가까운 내용이지만.. 열정을 봐서
<?php
$query = "SELECT
x.dateco_id,
(select count(*) from g5_board_new a
where a.dateco_id = x.dateco_id and addarea='작업지시') workcnt,
(select count(*) from g5_board_new a
where a.dateco_id = x.dateco_id and addarea='승인대기') staycnt,
(select count(*) from g5_board_new a
where a.dateco_id = x.dateco_id and addarea='승인완료') endcnt
FROM (select distinct dateco_id g5_board_new
where dateco_id != '' and dateco_id != 'epro'
and dateco_id != 'admin' ORDER BY wr_id desc) x";
$sql = sql_query($query);
?>
<style type="text/css">
*{
padding:0;
margin:0;
}
table, tr, td{ border: 1px solid #ddd;
}
</style>
<table class="table table-bordered">
<tr>
<th >아이디</th>
<th >작업지시</th>
<th >승인대기</th>
<th >승인완료</th><!--
<th >승인거절</th>
<th >작업완료</th>
<th >기간만료</th>-->
</tr>
<?php while($row= sql_fetch_array($sql)) { ?>
<tr>
<td><?php echo $row["dateco_id"]; ?></td>
<td> <?php echo $row['workcnt']?></td>
<td> <?php echo $row['staycnt']?></td>
<td> <?php echo $row['endcnt']?></td>
</tr> <?php } ?>
</table>
하시면
원하는 값들을 사용하실수있습니다.
이렇게 쿼리 하시면 되는거 아닌가요?
select dateco_id
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3
from g5_board_new out
그 부분을 별도 카운팅의 쿼리를 해서 처리해 주셔야 할듯 보여 집니다. 한번에 카운팅을 해서 처리할수 있는 부분이 아닌부분 입니다.
고수시네염 ㄷㄷ
답변을 작성하시기 전에 로그인 해주세요.